Engr 101Fall 2003

Number System NotesBlandford/Mitchell

Every number system has a unique base, b and numbers are expressed in terms of powers of that base. A number system of base b has b digits. For example in the decimal number system the base is 10 and there are 10 digits (0 to 9). A number such as 4697.34 can be written like this:

...

0 0 4 6 9 7 . 3 4

which is interpreted as

4x1000 + 6x100 + 9x10 + 7x1 + 3x0.1 + 4x0.01 = 4697.34

Other number bases work the same way. In computer science and computer engineering the most important and useful number bases are 2 (binary), 8 (octal), 10 (decimal), and 16 (hexadecimal). Decimal is useful because that's what humans use. Binary is useful since the two digits (0 and 1) can be used to represent the state of a switch and today, almost all computers are binary computers. Octal and hexadecimal are useful since they give us a shorthand way of writing the many digits in the binary number system.

Binary to Decimal Conversion

To convert a number from binary to decimal simply express the binary digits as powers of two and add them up in the decimal number system. For example the number

0110101 becomes

25 + 24 + 22 + 20 = 32 + 16 + 4 + 1 = 53 in base 10. So we can write 01101012 = 5310

Decimal to Binary Conversion

To convert from decimal to binary we must successively find all of the powers of two in the decimal number. We typically begin with finding the largest power of two and working down. For example suppose we want to convert 26510 to binary. The largest power of 2 in 265 is 28 = 256. Subtract 256 from 265 to get 9. The largest power of two in 9 is 23 = 8. Subtract 8 from 9 to get 1 which is 20. So 265 is 28 + 23 + 20. Thus we can write 26510 = 1000010012.

Binary to Octal and Octal to Binary Conversion

The octal number system uses base 8. Since 8 = 23 there is a simple way to convert base 8 numbers to base 2 and vice-versa. Each of the 8 digits 0 to 7 in octal is represented by 3 binary digits as shown in the Table 1.

Binary / Octal
000 / 0
001 / 1
010 / 2
011 / 3
100 / 4
101 / 5
110 / 6
111 / 7

Table 1

Use this table to convert binary to octal and vice-versa.

For example to convert 7638 to base 2 simply replace each octal digit by its binary equivalent from the table. Thus 7638 = 111 110 011. To convert binary to octal divide the binary digits into sets of three digits and look up the corresponding octal digits in the table. Add leading zeros as needed to get sets of 3. For example 1011011 has 7 digits. Add two leading zeros to get 001 011 011. Look up the corresponding octal digit for each binary triple. Thus 001 011 0112 = 1338.

Binary to Hex and Hex to Binary Conversion

The hexadecimal number system uses base 16 and thus has 16 digits. To get 16 digits we use the first 10 integers 0 to 9 and append the first 6 letters A to F to represent the digits for 10, 11, 12, 13, 14, and 15. Table 2 shows the corresponding hex and binary digits. We use Table 2 for conversion between hex and base 2 in the same way we use Table 1 for conversion between octal and base 2.

Binary / Hex
0000 / 0
0001 / 1
0010 / 2
0011 / 3
0100 / 4
0101 / 5
0110 / 6
0111 / 7
1000 / 8
1001 / 9
1010 / A
1011 / B
1100 / C
1101 / D
1110 / E
1111 / F

Table 2

Use this table to convert binary to hexadecimal and vice-versa.

For example, to convert FA9716 to binary we replace each hex digit with its corresponding binary from the table. Thus, FA9716 = 1111 1010 1001 01112

To convert binary to hex, divide the binary digits into sets of four digits and look up the corresponding hex digits in the table. Add leading zeros as needed to get sets of 4. For example 1011011 has 7 digits. Add one leading zero to get 0101 1011. Look up the corresponding binary digit for each binary set of 4. Thus 0101 10112 = 5B16.

Hexadecimal and octal are used as shorthand ways of expressing long binary patterns. Thus it's easier to talk and write about address 0C000h instead of binary address

1100 0000 0000 0000 which the computer actually uses. Note that it is customary to begin all hex numbers that start with a letter with a leading zero as a way of noting that it is a number and not a label. Thus C000h is written as 0C000h.

Exercises

1. 123410 = ______16 = ______8 = ______2

2. 394216 = ______2 = ______10

3. 10110101111012 = ______16 = ______10

4. 99.062510 = ______2 = ______16

5. 23AF16 = ______8