Hardware Reference
In-Depth Information
Example B.4
Convert the decimal number 59.75 to binary.
Solution: Since the given number has both the integral and fractional parts, they need to be con-
verted separately and then combined together. The conversion process is shown in Figure B.4.
a. Integral part
b. Fractional part
0.75
× 2
1.50
×2
1.00
2
59
1
lsb
2
29
1
msb
2
14
0
2
7
1
31
lsb
2
msb
2
1
1
0
Converted number = 111011.11 2
Figure B.4 Convert a decimal number with
both integral and fractional parts to binary
B.4 Why Octal and Hexadecimal Numbers?
After the computation, the computer needs to output the result so that the user can see and
determine whether the result is correct. The result can be displayed in either binary or decimal
format. To display a number in binary format is not convenient because it takes many 0s and
1s to represent a large number. To display a number in decimal format will require the computer to
perform some complicated conversion operations. The method to convert a binary number
to decimal is illustrated in Example 4.5. A compromise is to use octal or hexadecimal format to
represent a number. Hexadecimal representation is used more often than octal representation.
The shorthand of hexadecimal is hex .
B.5 Convert from Binary to Octal
The octal number system uses digits 0 through 7 to represent a number. The digit 0 corre-
sponds to 000 2 whereas the digit 7 corresponds to 111 2 . There are two steps to convert a binary
number to octal.
Step 1
Partition the given number (a string of 0s and 1s) from right to the left into groups of 3 bits.
Add leading 0s if the leftmost group has less than 3 bits.
Step 2
Convert each 3-bit group to the corresponding octal digit (0 to 7).
Search WWH ::




Custom Search