Binary place values

Computers store everything as binary: 0s and 1s, because a circuit is either off or on. Each bit is worth twice the one to its right.

1286432168421
10110010

1011 0010 = 128 + 32 + 16 + 2 = 178. To go the other way, take the biggest place value that fits, write 1, subtract, and carry on.

Tap the bits to see the value change.

Hexadecimal

Hexadecimal (base 16) uses the digits 0 to 9 and then A = 10, B = 11, C = 12, D = 13, E = 14, F = 15. Its place values are 1, 16, 256.

  • Hex to denary: 3C = 3 × 16 + 12 = 60.
  • Denary to hex: 200 ÷ 16 = 12 remainder 8, so C8.
  • Binary to hex: split into groups of four bits (nibbles) from the right. 1011 0010 = B2.

Programmers use hex because it is much shorter than binary, easier to read and copy without mistakes, and converts to binary in one step. Computers still store binary: hex is for people. You will see it in colour codes (#FF8800), memory addresses and MAC addresses.

Units of data

UnitSize
bita 0 or a 1
nibble4 bits
byte8 bits
kilobyte (kB)1000 bytes
megabyte (MB)1000 kB
gigabyte (GB)1000 MB
terabyte (TB)1000 GB

Some questions use 1024 instead of 1000. The binary prefixes say so in their names: 1 kibibyte (KiB) = 1024 bytes, 1 mebibyte (MiB) = 1024 KiB, 1 gibibyte (GiB) = 1024 MiB and 1 tebibyte (TiB) = 1024 GiB, because 1024 = 2^10. Use whichever the question says; elsewhere this course uses 1000.

n bits give 2^n different values: 8 bits give 256, from 0 to 255. To give k things their own code, find the smallest n with 2^n at least k.

Binary to denary

Write the place values above the bits, then add the ones under a 1.