Conversion among binary, octal, and hexadecimal systems
1. The Key Relationship
Octal and hexadecimal are not independent of binary — they are shorthand for it, because their bases are powers of 2:
| System | Bits per digit | Grouping rule |
|---|---|---|
| Binary ↔ Octal | 3 | Group the bits in 3s |
| Binary ↔ Hex | 4 | Group the bits in 4s |
Because the grouping is exact, binary ↔ octal/hex conversion needs no division — you simply re-group the bits, which is why programmers use octal/hex to write machine code and addresses compactly.
2. Binary to Octal
Group from the LSB towards the MSB in threes; pad the most significant group with zeros if it is short. For fractions, group from the binary point to the right, padding the last group.
Example:
| Grouping | 001 | 011 | 101 |
|---|---|---|---|
| Octal digit | 1 | 3 | 5 |
With a fraction: → integer 1|011|101 = 135, fraction 110|100 (padded) = .64 → 135.64₈
3. Octal to Binary
Replace each octal digit by its 3-bit equivalent (write leading zeros as needed).
Example:
4. Binary to Hexadecimal
Group from the LSB in fours and replace each group by its hex symbol (A-F for 10-15).
Example:
| Grouping | 1011 | 1010 | 1101 |
|---|---|---|---|
| Hex | B | A | D |
5. Hexadecimal to Binary
Expand each hex digit into 4 bits.
Example:
— note that each hex digit always produces 4 bits, even if the leading bit is 0.
6. Octal ↔ Hexadecimal (through binary)
There is no power relationship between 8 and 16, so convert via binary (or via decimal):
7. Decimal to Octal / Hexadecimal — Repeated Division
Divide by the base and read the remainders upwards.
Example:
| Division | Quotient | Remainder |
|---|---|---|
| 431 ÷ 8 | 53 | 7 |
| 53 ÷ 8 | 6 | 5 |
| 6 ÷ 8 | 0 | 6 |
431₁₀ = 657₈
Example:
| Division | Quotient | Remainder |
|---|---|---|
| 431 ÷ 16 | 26 | 15 = F |
| 26 ÷ 16 | 1 | 10 = A |
| 1 ÷ 16 | 0 | 1 |
431₁₀ = 1AF₁₆
8. Quick Reference Table
| Decimal | Binary (4-bit) | Octal | Hex |
|---|---|---|---|
| 8 | 1000 | 10 | 8 |
| 10 | 1010 | 12 | A |
| 15 | 1111 | 17 | F |
| 16 | 1 0000 | 20 | 10 |
| 255 | 1111 1111 | 377 | FF |
| 256 | 1 0000 0000 | 400 | 100 |
9. Common Mistakes to Avoid
- Grouping from the left (MSB) instead of the right — the LSB group must be complete (pad on the left).
- Using 4-bit groups for octal or 3-bit groups for hex.
- Forgetting to pad the fractional group at the right end.
- Writing a valid hex digit sequence but forgetting that A-F are single digits (10-15).
10. Exam Points
- Convert binary to octal and hex and back, showing the grouping — 5 marks, almost certain.
- Convert a decimal number to octal and hexadecimal by repeated division — 5 marks.
- Why is hex a shorthand for binary but octal is not a shorthand of hex? — 3 marks.
- Convert an octal number to hexadecimal via binary — 3-5 marks.
- Given a number in one base, express it in all four bases — 5 marks.