A1.2.1 — Binary & Hexadecimal

← Back to A1.2 overview

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.

Place values — each bit is a power of 2, starting from 20 on the right:
Bit2726252423222120
Value1286432168421

Binary → Decimal

  1. Write place values above each bit.
  2. Multiply each 1 by its place value.
  3. Add all products together.

Example: 10112 → 1×8 + 0×4 + 1×2 + 1×1 = 11

Decimal → Binary

  1. Divide by 2 repeatedly until you reach 0.
  2. Record the remainder at each step (0 or 1).
  3. Read remainders bottom to top — that is your binary number.
  4. 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.

HexBinaryDecimalHexBinaryDecimal
000000810008
100011910019
200102A101010
300113B101111
401004C110012
501015D110113
601106E111014
701117F111115

Hex → Decimal

  1. Convert any letters to their decimal value (A=10 … F=15).
  2. Multiply each digit by its place value (powers of 16, right to left: 160, 161, 162…).
  3. Add all products.

Example: FFF16 → F×256 + F×16 + F×1 = 3840 + 240 + 15 = 4095

Decimal → Hex

  1. Divide by 16 repeatedly until you reach 0.
  2. Convert remainders >9 to A–F.
  3. 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

  1. Split the binary number into groups of 4 bits (nibbles), starting from the right.
  2. Pad the leftmost group with leading zeros if fewer than 4 bits.
  3. Convert each nibble to its hex equivalent using the table above.

Example: 110101102 → 1101 | 0110 → D | 6 → D6

Hex → Binary

  1. Convert each hex digit to its 4-bit binary equivalent.
  2. Concatenate all the 4-bit groups.

Example: D5616 → D=1101, 5=0101, 6=0110 → 110101010110