Syllabus: Computer Science
1.1 Free

Number systems

Binary, denary and hexadecimal, converting between them, binary addition, overflow, logical shifts and two's complement.

Why computers use binary

A computer is built from billions of tiny switches. Each switch is either off or on, so the simplest number system for a computer has just two digits: 0 and 1. This is called binary.

Humans usually count in denary (base 10, digits 0 to 9). Programmers also use hexadecimal (base 16) because it is a short way to write long binary numbers.

SystemBaseDigits used
Binary20, 1
Denary100 to 9
Hexadecimal160 to 9 and A to F

Binary place values

Each binary digit (bit) has a place value that doubles as you move left.

1286432168421
01011011

Worked example: binary to denary

Add the place values that have a 1:

64 + 16 + 8 + 2 + 1 = 91

Worked example: denary to binary

Convert 45. Find which place values add up to 45:

32 + 8 + 4 + 1 = 45, so the binary number is 00101101.

Hexadecimal in one minute

One hex digit stands for exactly four bits, so split a binary number into groups of four:

0101 1011
  5    B     ->  5B

So binary 01011011 is 5B in hexadecimal, which is 91 in denary.

Try it yourself

  1. 1Convert 10110 from binary to denary.
  2. 2Convert 58 from denary to 8-bit binary.
  3. 3Convert 11110000 to hexadecimal.

Answers: 1) 22 2) 00111010 3) F0