Number Systems

From Coder Merlin
Within these castle walls be forged Mavens of Computer Science ...
— Merlin, The Coder

Positional Notation[edit]

Positional notation (sometimes called place-value notation) is a method of encoding numbers. It differs from other notations (such as Roman numerals) in that it uses the same symbol for different orders of magnitude depending on its position. For example, consider the number 23. The “3” indicates 3 ones, because it is in the ones position. The “2”, however, indicates 2 tens, because it is in the tens position. We know the value of a position by its location within the number. As we move left in a number, each position is valued at ten times the prior position. It might help if we label each position using power notation. Consider the number 123:

Positional Notation.png

The “3” is the right-most, and therefore the lowest-valued position, representing “ones” with a position multiplier of 100 (that is, 10 raised to the zero power, or 1). The “2” is located one position to the left, so we multiply by 10 again giving us a position multiplier of 101 (that is, 10 raised to the first power, or 10). Finally, the “1” is located one position to the left, so we again multiply by 10 giving us a position multiplier of 102 (that is, 10 raised to the second power, or 100). By multiplying each digit by its corresponding position multiplier, we can obtain the value of the entire number:

1 * 102 + 2 * 101 + 3 * 100 =
100 + 20 + 3 =
123

While we generally understand the mechanics of this process in the decimal system, thinking about how it actually works will enable us to consider other systems.

Number Base[edit]

The radix or base is the number of unique digits, including zero, used to represent numbers in a positional numeral system. The base is normally written as a subscript to the right of the number. For example, the decimal number 123 would formally be written as (123)10
Note that the parentheses are sometimes not written: 12310
In the case of decimal (base 10) numbers, the subscripted 10 is often assumed and not written.

Decimal System[edit]

The decimal system is the system with which we are most familiar. It is a decimal system because it contains ten unique digits:

0 1 2 3 4 5 6 7 8 9

For any (integer) value larger than 9, we’re required to use positional notation. Please keep in mind that “10” is not a digit. Rather, it’s a number consisting of two digits, a “1” in the tens (101) position and a “0” in the ones position (100).

Octal System[edit]

The octal system uses eight unique digits to represent a number:

0 1 2 3 4 5 6 7

Let’s consider the value of an octal number: 47358

What is the decimal value of this number? We use exactly the same method that we use for knowing the value in any system:

Digit at position: 4 7 3 5
Position multiplier: 83 82 81 80
Position value: 4 • 83 7 • 82 3 • 81 5 • 80
2048 448 24 5

Note that in this case, the right-most digit is, as always, representative of units (ones), just as in any positional system. However, moving one digit to the left, because we’re now using an octal system, the position indicates the number of eights (not tens). The next position to the left indicates the number of sixty-fours (not hundreds) and the final position indicates the number of 512’s. As before, we multiply each digit by its corresponding position multiplier to obtain the value of the entire number:

4 • 83 + 7 • 82 + 3 • 81 + 5 • 80 =
2,04810 + 44810 + 2410 + 510 =
2,52510

Hexadecimal System[edit]

The hexadecimal (six and ten) uses sixteen digits to represent a number:

0 1 2 3 4 5 6 7 8 9 A B C D E F

Note that because we only have ten digits in our familiar decimal system, we use the letters A through F to represent the additional six digits in the hexadecimal system. Remember that these are digits, that is, A represents 10, B represents 11, and so on up to F which represents 15.

Let’s consider the value of a hexadecimal number: B59C16

What is the decimal value of this number?

Digit at position: B 5 9 C
Position multiplier: 163 162 161 160
Position value: B • 163 5 • 162 9 • 161 C • 160
45,056 1280 144 12

As always, we multiply each digit by its corresponding position multiplier to obtain the value of the entire number:

B • 163 + 5 • 162 + 9 • 161 + C • 160 =
45,05610 + 128010 + 14410 + 1210 =
46,49210

Binary System[edit]

The binary system (two) uses two digits to represent a number:

0 1

Let’s consider the value of a binary number: 1011 10102
What is the decimal value of this number?

Digit at position: 1 0 1 1 1 0 1 0
Position multiplier: 27 26 25 24 23 22 21 20
Position value: 1 • 27 0 • 26 1 • 25 1 • 24 1 • 23 0 • 22 1 • 21 0 • 20
128 0 32 16 8 0 2 0

Multiplying each digit by its corresponding position multiplier to obtain the value of the entire number:

1 • 27 + 0 • 26 + 1 • 25 + 1 • 24 + 1 • 23 + 0 • 22 + 1 • 21 + 0 • 20 =
12810 + 010 + 3210 + 1610 + 810 + 010 + 210 + 010 =
18610

Formal Representation[edit]

Let x be a string of digits, such that:

Then, the value of in any particular base, , is calculated as:

Converting from Decimal to Another Base[edit]

To convert a decimal (base 10) number to any other base, we simply repeatedly divide by the base until we have a quotient of zero. Specifically, the dividend starts with the number that we want to convert, the divisor will always be the base. The remainder of each successive operation indicates the digit in the new base first at the right-most position and then moving left. The quotient of each step becomes the dividend of the subsequent step.

Let’s first try converting the number 2810 to octal (base 8):

The dividend is the decimal number that we want to convert, in this case 28. The divisor is the base to which we want to convert, in this case 8. The remainder indicates each successive digit. We stop the process when the quotient is 0.

Step Dividend Divisor Quotient Remainder
1 28 8 3 4
2 3 8 0 3

So, 2810 is 348. (Remember that we read the remainder from bottom to top.)

Let’s try converting the number 56710 to octal:

Step Dividend Divisor Quotient Remainder
1 567 8 70 7
2 70 8 8 6
3 8 8 1 0
4 1 8 0 1

So, 56710 is 10678.

Let’s try converting the number 63,21510 to hexadecimal:

Step Dividend Divisor Quotient Remainder
1 63215 16 3950 15
2 3950 16 246 14
3 246 16 15 6
4 15 16 0 15

So, 63,21510 is hexadecimal [15][6][14][15], or more conventionally, F6EF16.
(Remembering that in hexadecimal, we use the digit “F” for 15, “E” for 14, etc.)


Finally, let’s convert the number 53410 to binary:

Step Dividend Divisor Quotient Remainder
1 534 2 267 0
2 267 2 133 1
3 133 2 66 1
4 66 2 33 0
5 33 2 16 1
6 16 2 8 0
7 8 2 4 0
8 4 2 2 0
9 2 2 1 0
10 1 2 0 1

So, 53410 is 10 0001 01102

Customs[edit]

  • It is customary to separate groups of three decimal digits by commas. For example: 123,45610.
  • It is customary to separate groups to two hexadecimal digits by spaces and prefix a leading zero to what would otherwise be a single digit. For example: 01 2F16.
  • It is customary to separate groups of three octal digits by spaces and prefix leading zeros to pad to a three digit grouping. For example: 001 2378.
  • It is customary to separate groups of four binary digits by spaces and prefix leading zeroes to pad to a four digit grouping. For example: 0001 1011 11002.

Exercises[edit]

Quiz A: From Decimal[edit]

1 Convert 7910 to hexadecimal:

3216
7H16
4F16
5F16

2 Convert 7910 to octal:

1178
1158
1218
1198

3 Convert 7910 to binary:

0110 10102
0110 10002
0101 11112
0100 11112

4 Convert 88710 to hexadecimal:

03 7716
04 7916
02 7916
03 7916

5 Convert 88710 to octal:

001 5678
001 2778
002 5678
000 3678

6 Convert 88710 to binary:

0111 0111 01112
0011 0111 01112
0011 0111 11112
0000 0111 01112

7 Convert 7,58310 to hexadecimal:

D1 8F16
D1 9F16
1D 9F16
1E 9F16

8 Convert 7,58310 to octal:

016 5378
116 2378
016 6378
216 6378

9 Convert 7,58310 to binary:

0001 1101 1011 11112
0010 1101 1001 11112
0001 1101 1001 11112
0001 1101 1001 11102

10 Convert 9,04010 to hexadecimal:

32 7016
23 4E16
23 5816
23 5016

11 Convert 9,04010 to octal:

021 7208
021 5258
021 5208
023 5208

12 Convert 9,04010 to binary:

0010 0011 0111 00002
0011 0011 0101 00002
0010 0011 0101 00002
0010 0011 0101 01002


Quiz B: To Decimal[edit]

1 Convert 1A C716 to decimal:

6,85510
6,84510
6,85310
5,85510

2 Convert 0E 8D16 to decimal:

5,72510
4,70510
3,72310
3,72510

3 Convert 05 5516 to decimal:

1,36210
1,76510
1,70510
1,36510

4 Convert 0D 4016 to decimal:

3,50210
3,39210
3,19210
5,39210

5 Convert 24 DB16 to decimal:

9,73510
9,13510
9,43510
7,43510

6 Convert 7F FD16 to decimal:

31,76510
33,66510
32,76710
32,76510

7 Convert 001 0048 to decimal:

61610
50610
51610
53610

8 Convert 007 6648 to decimal:

4,02010
4,03010
2,02010
4,12010

9 Convert 167 2208 to decimal:

60,07210
57,10210
57,19210
61,07210

10 Convert 020 6328 to decimal:

8,59210
8,62210
8,60210
8,61210

11 Convert 1608 to decimal:

11210
10210
9210
11610

12 Convert 0100 0000 00112 to decimal:

1,03710
1,12710
1,02710
1,02310

13 Convert 0010 00102 to decimal:

2410
13410
3410
11410

14 Convert 1010 0111 0110 10012 to decimal:

32,80710
42,85710
42,80710
32,85710

15 Convert 1110 0011 1010 00102 to decimal:

57,27410
58,17410
58,27410
58,07410

16 Convert 1110 1110 1001 00002 to decimal:

60,07210
61,07210
61,17210
60,07410

17 Convert 0001 1011 1111 11102 to decimal:

7,16810
7,16610
7,26610
7,15610


References[edit]