4.3 Number Bases: Binary, Octal, Decimal, and Hexadecimal
Key Takeaways
- In a positional number system with base b, each digit is multiplied by a power of b: binary uses powers of 2, octal powers of 8, decimal powers of 10, and hexadecimal powers of 16.
- One hexadecimal digit stands for exactly 4 bits, and one octal digit stands for exactly 3 bits, so converting between binary and these bases only requires grouping bits.
- To convert a decimal integer to base b, divide repeatedly by b and read the remainders from last to first.
- Hexadecimal digits A through F represent the values 10 through 15; for example, E7 in hexadecimal equals 14 × 16 + 7 = 231 in decimal.
- To compare numbers written in different bases, convert them all to one base, usually decimal, before comparing.
What this competency asks
ETS asks you to understand number base conversion and binary, decimal, and hexadecimal number systems:
- Convert between number bases.
- Analyze and compare representations of numbers in different bases.
The discussion questions also mention octal, so be ready for base 8. Expect questions such as "What is the hexadecimal representation of this decimal number?" or "Which of these values is largest?", with the values written in mixed bases.
Positional notation
In base b, each position is worth a power of b, starting from b⁰ = 1 at the right. Each digit must be less than b.
| Base | Name | Digits | Place values (right to left) |
|---|---|---|---|
| 2 | Binary | 0, 1 | 1, 2, 4, 8, 16, 32, 64, 128, … |
| 8 | Octal | 0–7 | 1, 8, 64, 512, … |
| 10 | Decimal | 0–9 | 1, 10, 100, 1000, … |
| 16 | Hexadecimal | 0–9, A–F | 1, 16, 256, 4096, … |
In hexadecimal, A = 10, B = 11, C = 12, D = 13, E = 14, F = 15. A subscript shows the base (E7₁₆, 11100111₂). Programming languages often use prefixes instead: 0x for hex, 0b for binary.
Powers of 2 worth memorizing
| 2⁰ | 2¹ | 2² | 2³ | 2⁴ | 2⁵ | 2⁶ | 2⁷ | 2⁸ | 2⁹ | 2¹⁰ |
|---|---|---|---|---|---|---|---|---|---|---|
| 1 | 2 | 4 | 8 | 16 | 32 | 64 | 128 | 256 | 512 | 1024 |
Converting to decimal: expand by place value
Multiply each digit by its place value and add.
Binary to decimal: 11010110₂
| Place value | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
|---|---|---|---|---|---|---|---|---|
| Digit | 1 | 1 | 0 | 1 | 0 | 1 | 1 | 0 |
128 + 64 + 16 + 4 + 2 = 214.
Hexadecimal to decimal: 3A4₁₆ = 3 × 256 + 10 × 16 + 4 × 1 = 768 + 160 + 4 = 932.
Octal to decimal: 1365₈ = 1 × 512 + 3 × 64 + 6 × 8 + 5 × 1 = 512 + 192 + 48 + 5 = 757.
Converting from decimal: repeated division
To convert a decimal integer to base b, divide by b, record the remainder, and repeat with the quotient until the quotient is 0. Read the remainders from bottom to top: the last remainder is the most significant digit.
156 to binary
| Division | Quotient | Remainder |
|---|---|---|
| 156 ÷ 2 | 78 | 0 (least significant) |
| 78 ÷ 2 | 39 | 0 |
| 39 ÷ 2 | 19 | 1 |
| 19 ÷ 2 | 9 | 1 |
| 9 ÷ 2 | 4 | 1 |
| 4 ÷ 2 | 2 | 0 |
| 2 ÷ 2 | 1 | 0 |
| 1 ÷ 2 | 0 | 1 (most significant) |
Reading upward: 156 = 10011100₂. Check: 128 + 16 + 8 + 4 = 156.
500 to hexadecimal
| Division | Quotient | Remainder |
|---|---|---|
| 500 ÷ 16 | 31 | 4 |
| 31 ÷ 16 | 1 | 15 → F |
| 1 ÷ 16 | 0 | 1 |
Reading upward: 500 = 1F4₁₆. Check: 1 × 256 + 15 × 16 + 4 = 256 + 240 + 4 = 500.
ETS's sample question on this topic converts 231 to hexadecimal. Because 231 = 14 × 16 + 7, the answer is E7₁₆. The wrong choices differ by a single digit or a misplaced remainder, so always check your answer by converting back.
A faster alternative for binary is subtracting powers of 2. For 156, the largest power of 2 that fits is 128, leaving 28. Then 16 fits, leaving 12. Then 8, leaving 4. Then 4, leaving 0. Place 1s under 128, 16, 8, and 4 and 0s everywhere else.
Binary ↔ hexadecimal and octal: group the bits
Because 16 = 2⁴, each hex digit is exactly 4 bits (a nibble). Because 8 = 2³, each octal digit is exactly 3 bits.
Binary to hex: group from the right in fours, padding the leftmost group with zeros.
1011110101₂ → 0010 1111 0101 → 2, F, 5 → 2F5₁₆
Binary to octal: group from the right in threes.
1011110101₂ → 001 011 110 101 → 1, 3, 6, 5 → 1365₈
Hex to binary: replace each hex digit with its 4 bits.
9C7₁₆ → 9 = 1001, C = 1100, 7 = 0111 → 100111000111₂
All three results for 1011110101₂ agree: 2F5₁₆ = 1365₈ = 757₁₀.
Reference table, 0–15
| Decimal | Binary | Octal | Hex |
|---|---|---|---|
| 0 | 0000 | 0 | 0 |
| 1 | 0001 | 1 | 1 |
| 2 | 0010 | 2 | 2 |
| 3 | 0011 | 3 | 3 |
| 4 | 0100 | 4 | 4 |
| 5 | 0101 | 5 | 5 |
| 6 | 0110 | 6 | 6 |
| 7 | 0111 | 7 | 7 |
| 8 | 1000 | 10 | 8 |
| 9 | 1001 | 11 | 9 |
| 10 | 1010 | 12 | A |
| 11 | 1011 | 13 | B |
| 12 | 1100 | 14 | C |
| 13 | 1101 | 15 | D |
| 14 | 1110 | 16 | E |
| 15 | 1111 | 17 | F |
Analyzing and comparing representations
- Comparing values: convert everything to decimal first. Example: which is largest, 3F₁₆, 1000000₂, 77₈, or 62₁₀? The values are 63, 64, 63, and 62, so 1000000₂ is largest.
- Digit count: the same value needs more digits in a smaller base. 255 is
11111111in binary (8 digits),377in octal (3 digits), andFFin hex (2 digits). That compactness is why programmers use hex. - Range of n digits: n binary digits represent 2ⁿ different values, from 0 to 2ⁿ − 1. Two hex digits (one byte) cover 0–255.
- Recognizing invalid numbers:
129₈is not a valid octal number, because octal has no digit 9.1G₁₆is not valid hex. - Quick parity check: a binary number is even exactly when its last bit is 0.
Where each base appears in computing
| Base | Common uses |
|---|---|
| Binary | How hardware stores and processes all data |
| Hexadecimal | Memory addresses, color codes such as #FF8800, MAC addresses, IPv6 addresses, byte dumps |
| Octal | Unix file permissions, such as chmod 755 (rwxr-xr-x) |
| Decimal | Human-facing input and output |
Chapter 13 builds on these conversions with bits and bytes, character codes, colors, and two's complement.
What is the decimal value of 2E₁₆, and what is its 8-bit binary representation?
Which of the following values is the largest?
What is the hexadecimal representation of the decimal number 200?