Binary and octal numbers share a very special relationship: Given a number in binary, you can read it off in octal; given a number in octal, you can read it off in binary.

For example, take the octal number **453.** If you replace each digit with the binary representation of that digit, you have 453 in binary. That is,

**4**in octal is 100 in binary,**5**in octal is 101 in binary,**3**in octal is 011 in binary,

so **453** in octal is **100101011** in binary.

To convert from binary to octal, you start at the **rightmost** binary digit and mark the digits in **groups of threes.** Then you convert each group of three to its octal value:

100 ---- |
101 ---- |
011 ---- |

4 | 5 | 3 |

The reason that binary can be immediately converted to octal and octal to binary is that **8 is a power of 2.** There is a similar relationship between binary and hexadecimal.

Every hexadecimal digit can be represented in **four binary digits.** Let us take the binary number **100101011** and convert it to hexadecimal by marking the digits from right to left in groups of four:

1 ----- |
0010 ----- |
1011 ----- |

1 | 2 | B |

The rules for converting base-10 numbers involve **dividing by the base** into which you are converting the number.

From this division, you get a quotient and a remainder. The remainder becomes the next digit in the new number (going from right to left), and the quotient replaces the number to be converted.

The process continues until the quotient is zero:

Divide the decimal number by the new base

Make the remainder the next digit to the left in the answer

Replace the decimal number with the quotient

The above **pseudocode** forms an **algorithm** for converting from base 10 another base.

The first line of the algorithm tells us to repeat the next three lines until the quotient from our division becomes zero.

Decimal **299** into hexadecimal is:

299 / 16 | = | 18 Remainder | = | (11) B |

18 / 16 | = | 1 Remainder | = | 2 |

1 / 16 | = | 0 Remainder | = | 1 |

--------- 12B |

The quotient is zero, so we are finished, and the final answer is **12B.**