#### Binary/Octal/Hexadecimal Conversions

A very convenient property of number bases is this:
If A = B^{N}, then each digit in
a base A number will be exactly N digits in the base B number.

Since 16 = 2^{4}, each hexadecimal digit
corresponds to exactly 4 bits.

Since 8 = 2^{3}, each octal digit
corresponds to exactly 3 bits.

Hence, when converting between binary and either octal or hex,
we can convert one octal or hex digit at a time. There is no
long multiplication or division necessary. We simply convert one
octal or hex digit at a time using
Table 15.5, “Binary/Octal Conversion” or
Table 15.6, “Binary/Hex Conversion”, or convert each group of
3 or 4 bits. With a little practice,
you will have this table memorized and be able to "see" the bits
in an octal or hex number at a glance.

**Table 15.5. Binary/Octal Conversion**

Binary | Octal |
---|

000 | 0 |

001 | 1 |

010 | 2 |

011 | 3 |

100 | 4 |

101 | 5 |

110 | 6 |

111 | 7 |

**Table 15.6. Binary/Hex Conversion**

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 |

For this reason, we use octal or hexadecimal to represent values
where we want to know the values of individual bits. Binary
numbers tend to be long, so we represent them in hex or octal to
save space. The lower the base, the more digits it takes to
represent a typical value.

FFC3.2_{16}
= 1111 1111 1100 0011 . 0010_{2}

374.4_{8}
= 011 111 100 . 100_{2}

When converting from binary to base 2^{N},
we need to be careful.
Always group bits beginning at the radix point and move outward.
The number of bits may not be a multiple of N, so we may have to
pad the leftmost group with leading 0s and the rightmost group with
trailing 0s.

11001.11_{2} = 011 001 . 110_{2}
= 31.6_{8}

111010.011_{2}
= 0011 1010 . 0110_{2}
= 3A.6_{16}

### Note

When converting large numbers from decimal to binary or from binary
to decimal, smart people first convert to hexadecimal.
This greatly reduces the number of steps in long multiplication or
long division. People who are paid by the hour to do manual
number conversions are not advised to use this shortcut.
How many bits would each base 32 digit represent?

Perform the following conversions.

11FC.2_16 to binary

1100101111.01_2 to hex

773550.5_8 to binary

1001001010010.1_2 to octal