Number systems

Computer Science · Data representation. The idea in plain words, the rules to remember, the mistake to avoid and a worked example, written and checked by Mega Lecture.

Test this topic freeAll Computer Science topics

The idea

A computer is built from millions of tiny switches that are either on or off. So all data, whether numbers, text, sound or images, is stored as binary: patterns of 1s and 0s.

Denary uses place values 1, 10, 100. Binary uses 1, 2, 4, 8, 16, 32, 64, 128. Hexadecimal uses 16 digits, 0 to 9 then A to F (A = 10, F = 15). One hex digit stands for exactly four bits, so hex is shorter and easier for people to read than binary.

You must also add 8-bit numbers, shift them left or right, and write negative numbers in two's complement, where the left-most bit is worth −128.

In simpler words

A computer is made of tiny switches that are on or off. So it stores everything as 1s and 0s, called binary. Each binary place is worth double the one to its right: 1, 2, 4, 8 and so on. Hexadecimal uses sixteen digits, 0 to 9 then A to F. One hex digit stands for four binary digits, so it is shorter to read.

An everyday comparison

Binary place values are like coins in a strange country with only 1, 2, 4, 8, 16, 32, 64 and 128 coins, one of each. To pay any amount up to 255, you pick which coins to use, and each coin is either used, 1, or not, 0. The comparison stops working for two's complement, where the biggest coin counts as minus 128.

Rules to remember

Common mistake

Students read a hex digit such as C as a denary 12 and then forget to multiply by its place value. In 3C the 3 is worth 3 × 16, not 3.

In the exam

Write the place value headings above the bits before converting, such as 128 64 32 16 8 4 2 1. For hex, convert each digit to four bits, or multiply each digit by its place value, 16 or 1. For addition, show the carries and state overflow if the result needs a ninth bit. For two's complement, write the positive number, invert every bit, then add 1, and check using −128.

Worked example

Convert the denary number 219 to hexadecimal.

  1. Divide by 16: 219 ÷ 16 = 13 remainder 11 (13 × 16 = 208, 219 − 208 = 11).
  2. 13 is the hex digit D and 11 is the hex digit B.
  3. Check in binary: D = 1101, B = 1011, and 1101 1011 = 128 + 64 + 16 + 8 + 2 + 1 = 219.

Answer: 219 in denary is DB in hexadecimal.

Ask about this

Type what you are stuck on. The helper finds the explanation, worked examples and the notes to read, free and instant.

Keep going

Text, sound and images →Take a Computer Science test