What is the largest decimal number that can be represented by
3 bits in binary? *Answer*: 7.

What is the largest decimal number that can be represented by
4 bits in binary? *Answer*: 15.

What is the largest symbol in octal? *Answer*: 7.

What is the *decimal value* of the largest symbol in hex? *Answer:* 15.

Do you see where we are headed? Let us make a table of decimal values and their binary, octal, and hex equivalents:

Dec | Bin | Oct | Hex | Dec | Bin | Hex | |
---|---|---|---|---|---|---|---|

0 | 0|000 | 0 | 0 | 8 | 1000 | 8 | |

1 | 0|001 | 1 | 1 | 9 | 1001 | 9 | |

2 | 0|010 | 2 | 2 | 10 | 1010 | A | |

3 | 0|011 | 3 | 3 | 11 | 1011 | B | |

4 | 0|100 | 4 | 4 | 12 | 1100 | C | |

5 | 0|101 | 5 | 5 | 13 | 1101 | D | |

6 | 0|110 | 6 | 6 | 14 | 1110 | E | |

7 | 0|111 | 7 | 7 | 15 | 1111 | F |

Notice that the left half of the table has all 4 bases, but the right half only has 3. This is because the left half of the table "uses up" the octal symbols. The other half is needed in order "finish off" the hex symbols. The table is produced by counting. In each column just count in the appropriate base. Stop at seven for the Dec, Oct, and Hex columns on the first half. Continue on the second half with all but the Oct column. This table allows us to take advantage of the "shorthand" that octal and hex are for binary. We notice that 3 binary bits are enough to use up all the octal digits and 4 bits use up hex. This means that if we group a binary number into groups of 3 bits we can just look up the 3 bit pattern in the table and write down the appropriate octal digit. Analogously, we can group a binary number into groups of 4 bits and just look up the 4 bit pattern in the table and write down the appropriate hex digit. Be careful to use 3 bits for octal and 4 bits for hex - this is why the vertical bar is added to the Bin column of the table, to remind you that octal only uses 3 bits.

**Example**

Convert binary 1011001110 to octal and to hex.

1) To convert to octal, group the binary into groups of 3 bits
- starting at the right side!

```
1 | 011 | 001 | 110
```

If we want to, we can always add 0's to the left of the number
- just like the 0's on the left of the odometer of a car, they
do not change the value of the number. We add two 0's here for
demonstration purposes:

```
001 | 011 | 001 | 110
```

Now just look up each group of 3 bits in the table (it is best
to have some convention for this, right to left makes the most
sense - just in case you mess up the groups of 3 bits). We look
up 110 in the Bin column of the table, it corresponds to 6 in
the Oct column. This is the one's digit in our answer:

```
001 | 011 | 001 | 110
6
```

We continue to look up each of the 3 bit groups, resulting in
our answer:

```
001 | 011 | 001 | 110
1 3 1 6
```

The result is then 1316(8).
2) To convert to hex, group into groups of 4 - starting at the
right side and padding with 0's on the left as needed:

```
0010 | 1100 | 1110
```

The rightmost group of 4 bits causes a problem if you do not pay
close attention - 1110 has a

```
0010 | 1100 | 1110
2 C E
```

Return to Tech Tips

Return to Mechatronics Homepage