Chapter 1

Number Systems: Binary and Hexadecimal

Discover how computers store numbers using base-2 binary and base-16 hexadecimal, and learn to convert between them and everyday denary.

Binary — the language of computers

Computers are built from switches that are either on or off, so they store everything using just two symbols, 0 and 1. This is the binary (base-2) number system. A single 0 or 1 is called a bit, and a group of eight bits is one byte. In binary, each column is worth twice the one to its right: 1, 2, 4, 8, 16, 32, 64, 128. Because there are only two states, binary is very reliable: a circuit only has to tell the difference between a high voltage and a low voltage, not many in-between levels that could easily be confused.

Key idea

To convert binary to denary, add up the place values wherever a 1 appears. For example 1010 = 8 + 0 + 2 + 0 = 10.

Hexadecimal — base 16

Long strings of bits are hard for people to read, so programmers often use hexadecimal (base 16). Hex uses sixteen digits: 0 to 9, then A, B, C, D, E, F, where A = 10 and F = 15. One hex digit represents exactly four bits (a nibble), so two hex digits describe one byte. Hexadecimal is common in memory addresses, colour codes and error messages.

Example

Convert hex 2F to denary: (2 × 16) + 15 = 47. Convert denary 255 to hex: 255 = FF.

Remember

  • 1 byte = 8 bits; 1 nibble = 4 bits.
  • Hex is shorter than binary, but the computer still stores everything as binary.
  • Count binary place values from the right: 1, 2, 4, 8, 16 and so on.

Stuck on this topic? A verified JomKelas tutor can walk you through it.

Find a verified tutor