A1.2.1 — Binary & Hexadecimal
Binary (Base-2)
Binary uses only digits 0 and 1. Every piece of data in a computer is stored and processed in binary. Binary numbers use a subscript 2 — e.g. 10112.
| Bit | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 |
|---|---|---|---|---|---|---|---|---|
| Value | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
Binary → Decimal
- Write place values above each bit.
- Multiply each 1 by its place value.
- Add all products together.
Example: 10112 → 1×8 + 0×4 + 1×2 + 1×1 = 11
Decimal → Binary
- Divide by 2 repeatedly until you reach 0.
- Record the remainder at each step (0 or 1).
- Read remainders bottom to top — that is your binary number.
- Pad with leading zeros to fill 8 bits if needed.
Example: 11 → divide: 11÷2=5 R1, 5÷2=2 R1, 2÷2=1 R0, 1÷2=0 R1 → read up: 1011 → 8-bit: 00001011
Hexadecimal (Base-16)
Hexadecimal uses 16 digits: 0–9 and A–F (A=10, B=11, C=12, D=13, E=14, F=15). Numbers use subscript 16 — e.g. C47B16. More human-readable than binary for large numbers.
Each hex digit is called a nibble and directly corresponds to exactly 4 binary bits, making conversion between them straightforward.
| Hex | Binary | Decimal | Hex | Binary | Decimal |
|---|---|---|---|---|---|
| 0 | 0000 | 0 | 8 | 1000 | 8 |
| 1 | 0001 | 1 | 9 | 1001 | 9 |
| 2 | 0010 | 2 | A | 1010 | 10 |
| 3 | 0011 | 3 | B | 1011 | 11 |
| 4 | 0100 | 4 | C | 1100 | 12 |
| 5 | 0101 | 5 | D | 1101 | 13 |
| 6 | 0110 | 6 | E | 1110 | 14 |
| 7 | 0111 | 7 | F | 1111 | 15 |
Hex → Decimal
- Convert any letters to their decimal value (A=10 … F=15).
- Multiply each digit by its place value (powers of 16, right to left: 160, 161, 162…).
- Add all products.
Example: FFF16 → F×256 + F×16 + F×1 = 3840 + 240 + 15 = 4095
Decimal → Hex
- Divide by 16 repeatedly until you reach 0.
- Convert remainders >9 to A–F.
- Read remainders bottom to top.
Example: 2040 → 2040÷16=127 R8, 127÷16=7 R15(F), 7÷16=0 R7 → read up: 7F8
Binary → Hex
- Split the binary number into groups of 4 bits (nibbles), starting from the right.
- Pad the leftmost group with leading zeros if fewer than 4 bits.
- Convert each nibble to its hex equivalent using the table above.
Example: 110101102 → 1101 | 0110 → D | 6 → D6
Hex → Binary
- Convert each hex digit to its 4-bit binary equivalent.
- Concatenate all the 4-bit groups.
Example: D5616 → D=1101, 5=0101, 6=0110 → 110101010110