Skip to content

Binary

Binary and hexadecimal explained

Why computers use binary, how to convert between binary, denary and hexadecimal, and how to answer every binary exam question. Try the converter as you go.

Why computers use binary

Computers are built from billions of tiny switches called transistors. Each switch is either off or on, which we write as 0 or 1. A single 0 or 1 is a bit. Eight bits make a byte. Everything a computer stores, from numbers to images to sound, is held as binary.

Try it: the binary converter

Click the bits to switch them on and off. Watch the denary and hexadecimal values change.

Binary to denary

Each column is worth double the one to its right. Add up the columns that have a 1.

1286432168421
01001101

01001101 = 64 + 8 + 4 + 1 = 77.

Denary to binary

  1. Write the column headings 128 to 1.
  2. Working left to right, put a 1 in any column you can subtract without going below zero, and subtract it.
  3. Put 0 in the others.

Example: 150 = 128 + 16 + 4 + 2 = 10010110.

Hexadecimal

Hexadecimal (base 16) uses 0 to 9 then A to F for 10 to 15. One hex digit stands for exactly four bits, a nibble, so hex is a shorter, easier way for humans to read binary. It is used for colour codes and memory addresses.

  1. Split the byte into two nibbles: 1001 0110.
  2. Convert each nibble: 1001 = 9, 0110 = 6.
  3. Join them: 96.

To convert hex to denary, multiply the left digit by 16 and add the right digit: 2F = 2 × 16 + 15 = 47.

Binary addition and overflow

0 + 00
0 + 11
1 + 10, carry 1
1 + 1 + 11, carry 1
  01101100   (108)
+ 00111010   ( 58)
----------
  10100110   (166)

If the answer needs more than eight bits, the extra carry has nowhere to go. That is an overflow error, and the stored result is wrong.

Binary shifts

A left shift of one place doubles the number. A right shift of one place halves it, losing any remainder. Bits that fall off the end are lost, which can make the result inaccurate.

Units of data

4 bits1 nibble
8 bits1 byte
1,000 bytes1 kilobyte (KB)
1,000 KB1 megabyte (MB)
1,000 MB1 gigabyte (GB)
1,000 GB1 terabyte (TB)
1,000 TB1 petabyte (PB)

GCSE specifications use multiples of 1,000. Check your board's specification.

Questions

Common questions

What is the largest number in 8 bits?

11111111, which is 255. With 8 bits you can store 256 different values, 0 to 255.

Why do programmers use hexadecimal?

It is shorter than binary and easier to read, with fewer mistakes, and converts directly because each hex digit is four bits.

Do I need a calculator?

No. Calculators are not allowed in most GCSE Computer Science papers, so practise the column method.

Want help with this one to one?

Dee replies personally to every enquiry, usually within two working days.

Send an enquiry