Information Technology Topic

Octal and Hexadecimal Conversion

  1. Read notes
  2. Flashcards
  3. Quiz
  4. Confident

Study focus - 3 things

  1. Octal is base 8 (digits 0 to 7) and hexadecimal is base 16 (digits 0 to 9 then A to F, where A = 10 up to F = 15)
  2. One octal digit is exactly 3 bits and one hexadecimal digit is exactly 4 bits, so binary converts by grouping the bits from the right
  3. To go to decimal, multiply each digit by its place value (powers of 8 or powers of 16) and add; to come from decimal, divide repeatedly by 8 or 16 and read the remainders from the bottom up

Section 1Why octal and hexadecimal?

Binary is what the computer uses, but a long string such as 110100111011 is easy to misread. Octal and hexadecimal are shorthand for binary that people find easier to read and copy. Octal is base 8. It has eight symbols, 0 to 7, and its place values are powers of 8: 1, 8, 64 … Hexadecimal (hex for short) is base 16. It needs sixteen symbols, so after 9 it uses letters: A = 10, B = 11, C = 12, D = 13, E = 14, F = 15. Its place values are powers of 16: 1, 16, 256 … This topic is whole numbers only.

Section 2Binary and octal: groups of three

Eight is 2 × 2 × 2, so exactly three bits make one octal digit. Here's the trick: memorise the eight patterns. Octal digit | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 Binary | 000 | 001 | 010 | 011 | 100 | 101 | 110 | 111 Binary to octal: group the bits in threes starting from the right, add zeros at the left if the last group is short, and write each group as one digit. 101110 splits as 101 | 110, which is 5 and 6, so 101110 = 56 in octal. Octal to binary is the reverse: turn each digit into three bits. Octal 47 is 100 | 111, so 100111.

Section 3Binary and hexadecimal: groups of four

Sixteen is 2 × 2 × 2 × 2, so exactly four bits make one hex digit. Hex digit | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 Binary | 0000 | 0001 | 0010 | 0011 | 0100 | 0101 | 0110 | 0111 Hex digit | 8 | 9 | A | B | C | D | E | F Binary | 1000 | 1001 | 1010 | 1011 | 1100 | 1101 | 1110 | 1111 Binary to hex: group the bits in fours from the right (pad with zeros on the left), and write each group as one hex digit. 10110011 splits as 1011 | 0011, which is B and 3, so 10110011 = B3. Watch out: always start grouping from the right. Grouping from the left gives a wrong answer when the number of bits is not a multiple of 3 or 4.

Section 4Octal and hexadecimal to decimal

Use place values, the same idea as in binary. Multiply each digit by its place value and add. Octal 345: Place value | 64 | 8 | 1 Digit | 3 | 4 | 5 3 × 64 + 4 × 8 + 5 × 1 = 192 + 32 + 5 = 229. Hex 2F (F means 15): Place value | 16 | 1 Digit | 2 | F 2 × 16 + 15 × 1 = 32 + 15 = 47. Another: hex A5 = 10 × 16 + 5 = 165.

Section 5Decimal to octal and hexadecimal

Repeated division again, but by 8 (octal) or 16 (hex). Keep the remainders and read them from the bottom up. Any remainder from 10 to 15 becomes a letter in hex. Decimal 100 to octal: 100 ÷ 8 = 12 remainder 4 12 ÷ 8 = 1 remainder 4 1 ÷ 8 = 0 remainder 1 Reading up: 144. Check: 64 + 32 + 4 = 100. Decimal 200 to hex: 200 ÷ 16 = 12 remainder 8 12 ÷ 16 = 0 remainder 12 The remainder 12 is the letter C, so reading up gives C8. Check: 12 × 16 + 8 = 200.

Section 6Octal to hexadecimal (and back): go through binary

There is no quick direct trick between base 8 and base 16, so use binary as the middle step. Turn the octal digits into 3-bit groups, join the bits, then regroup in fours. Octal 377: 3 | 7 | 7 becomes 011 | 111 | 111, which is 011111111. Regroup in fours from the right: 1111 | 1111, which is F and F. So octal 377 = hex FF = 255 in decimal. Going from hex to octal works the same way in the other direction.

Section 7Where you see them, and how to check

One byte is 8 bits, which is exactly two hex digits (4 bits each). That makes hex a neat way to write a byte: 11111111 is FF and 00101101 is 2D. Octal needs three bits per digit, so it fits a byte less neatly, but it is still a short way to write binary. Checks: every digit must be allowed in the base (no 8 or 9 in octal, no letter past F in hex). Convert your answer back to binary or decimal and make sure you get the number you started with.

Examples

A student in Portmore writes down the byte 10111011. (a) Convert it to octal. (b) Convert it to hexadecimal. (c) Check both answers by converting them to decimal.

(a) Group in threes from the right: 10 | 111 | 011. The left group is short, so pad it: 010 | 111 | 011. These are 2, 7 and 3, so the octal number is 273. (b) Group in fours from the right: 1011 | 1011. Each group is 11, which is B. The hex number is BB. (c) Octal 273: 2 × 64 + 7 × 8 + 3 = 128 + 56 + 3 = 187. Hex BB: 11 × 16 + 11 = 176 + 11 = 187. Both give 187, so the two answers agree with each other.

The computers in a school lab in Mandeville are numbered in decimal. Computer number 234 needs to be shown in hexadecimal, binary and octal. (a) Convert 234 to hexadecimal by repeated division. (b) Use your hex answer to write 234 in binary. (c) Use your binary answer to write 234 in octal, and check it.

(a) 234 ÷ 16 = 14 remainder 10 14 ÷ 16 = 0 remainder 14 The remainders are 10 (A) and 14 (E). Reading from the bottom up gives EA. (b) E = 1110 and A = 1010, so 234 = 11101010. (c) Group in threes from the right: 11 | 101 | 010. Pad the left group: 011 | 101 | 010, which is 3, 5 and 2, so the octal number is 352. Check: 3 × 64 + 5 × 8 + 2 = 192 + 40 + 2 = 234.

Now let's water it

Session runs notes to flashcards to quiz back-to-back.

Where this comes from