Number Systems
Curriculum[edit]
Coder Merlin™ Computer Science Curriculum Data  
Unit: Numbers Experience Name: Number Systems (W1011) Knowledge and skills:
Topic areas: Positional notation Classroom time (average): 60 minutes Study time (average): 180 minutes Successful completion requires knowledge: understand positional notation Successful completion requires skills: ability to use positional notation to represent numbers in the binary, octal, decimal, and hexadecimal systems; ability to convert between representations of numbers in the binary, octal, decimal, and hexadecimal systems 
Positional Notation[edit]
Positional notation (sometimes called placevalue 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:
The “3” is the rightmost, and therefore the lowestvalued position, representing “ones” with a position multiplier of 10^{0} (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 10^{1} (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 10^{2} (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 * 10^{2} + 2 * 10^{1} + 3 * 10^{0} =
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: 123_{10}
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 (10^{1}) position and a “0” in the ones position (10^{0}).
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: 4735_{8}
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:  8^{3}  8^{2}  8^{1}  8^{0} 
Position value:  4 • 8^{3}  7 • 8^{2}  3 • 8^{1}  5 • 8^{0} 
2048  448  24  5 
Note that in this case, the rightmost 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 sixtyfours (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 • 8^{3} + 7 • 8^{2} + 3 • 8^{1} + 5 • 8^{0} =
2,048_{10} + 448_{10} + 24_{10} + 5_{10} =
2,525_{10}
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: B59C_{16}
What is the decimal value of this number?
Digit at position:  B  5  9  C 
Position multiplier:  16^{3}  16^{2}  16^{1}  16^{0} 
Position value:  B • 16^{3}  5 • 16^{2}  9 • 16^{1}  C • 16^{0} 
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 • 16^{3} + 5 • 16^{2} + 9 • 16^{1} + C • 16^{0} =
45,056_{10} + 1280_{10} + 144_{10} + 12_{10} =
46,492_{10}
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 1010_{2}
What is the decimal value of this number?
Digit at position:  1  0  1  1  1  0  1  0 
Position multiplier:  2^{7}  2^{6}  2^{5}  2^{4}  2^{3}  2^{2}  2^{1}  2^{0} 
Position value:  1 • 2^{7}  0 • 2^{6}  1 • 2^{5}  1 • 2^{4}  1 • 2^{3}  0 • 2^{2}  1 • 2^{1}  0 • 2^{0} 
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 • 2^{7} + 0 • 2^{6} + 1 • 2^{5} + 1 • 2^{4} + 1 • 2^{3} + 0 • 2^{2} + 1 • 2^{1} + 0 • 2^{0} =
128_{10} + 0_{10} + 32_{10} + 16_{10} + 8_{10} + 0_{10} + 2_{10} + 0_{10} =
186_{10}
Formal Representation[edit]
Let x be a string of digits, such that:
Then, the value of in any particular base, , is calculated as:
The rightmost digit, is referred to as the least significant digit, or LSD. It is least significant because in terms of the overall value of the entire number, this digit will always have the least impact. Conversely, the leftmost digit, is referred to as the most significant digit, or MSD. It is most significant because in terms of the overall value of the entire number, this digit will always have the most impact.
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 rightmost position and then moving left. The quotient of each step becomes the dividend of the subsequent step.
Let’s first try converting the number 28_{10} 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, 28_{10} is 34_{8}. (Remember that we read the remainder from bottom to top.)
Let’s try converting the number 567_{10} 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, 567_{10} is 1067_{8}.
Let’s try converting the number 63,215_{10} 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,215_{10} is hexadecimal [15][6][14][15], or more conventionally, F6EF_{16}.
(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, 534_{10} is 10 0001 0110_{2}
Customs[edit]
 It is customary to separate groups of three decimal digits by commas. For example: 123,456_{10}.
 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 2F_{16}.
 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 237_{8}.
 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 1100_{2}.
Shortcut Conversions[edit]
Because both the octal and hexadecimal bases contain and possible digits, respectively, and the binary base contains possible digits, we're able to utilize a shortcut when converting between these systems. Note that each octal digit is comprised of three binary digits and each hexadecimal digit is comprised of four binary digits. We can therefore establish (and memorize) the following table:
Decimal  Binary  Octal  Hexadecimal 

00  0000  00  0 
01  0001  01  1 
02  0010  02  2 
03  0011  03  3 
04  0100  04  4 
05  0101  05  5 
06  0110  06  6 
07  0111  07  7 
08  1000  10  8 
09  1001  11  9 
10  1010  12  A 
11  1011  13  B 
12  1100  14  C 
13  1101  15  D 
14  1110  16  E 
15  1111  17  F 
The shortcut is very straightforward yet a significant time saver and based on the above information. When converting between binary, octal, and hexadecimal, there's no need to use an intermediate, decimal step.
Binary to Hexadecimal[edit]
Group the binary number in sets of four digits, from right to left. Each binary set represents a single hexadecimal digit. (It's sometimes helpful to pad the final set with zeroes.) For example, given the number , regroup the binary digits in sets of four:
.
Then, use the memorized table to translate each set of four binary digits to a single hexadecimal digit:
1100  0111  0010  0101 
C  7  2  5 
Hexadecimal to Binary[edit]
Simply follow the above procedure in reverse. Use the memorized table to convert each hexadecimal digit to a set of four binary digits.
Binary to Octal[edit]
Group the binary number in sets of three digits, from right to left. Each binary set represents a single octal digit. (It's sometimes helpful to pad the final set with zeroes.) For example, given the number , regroup the binary digits in sets of three:
.
Then, use the memorized table to translate each set of three binary digits to a single octal digit:
001  100  011  100  100  101 
1  4  3  4  4  5 
Octal to Binary[edit]
Simply follow the above procedure in reverse. Use the memorized table to convert each octal digit to a set of three binary digits.
Octal to Hexadecimal (and vice versa)[edit]
This requires slightly more work. Convert the number in the source base to binary, and then convert from binary to the target base.
Exercises[edit]
Exercises  

References[edit]
 Positional Notation (Wikipedia)
 Radix (Wikipedia)
Experience Metadata
Experience ID  W1011 

Unit  Numbers 
Knowledge and skills  §10.311 
Topic areas  Positional notation 
Classroom time  60 minutes 
Study time  3 hours180 minutes <br /> 
Acquired knowledge  understand positional notation 
Acquired skill  ability to use positional notation to represent numbers in the binary, octal, decimal, and hexadecimal systems ability to convert between representations of numbers in the binary, octal, decimal, and hexadecimal systems 
Additional categories 