About this experiment
Inside a computer every number, letter, picture and sound is stored as a pattern of switches that are either off or on: 0 or 1. Each switch is a bit. Just as each column in our decimal numbers is worth ten times the one to its right, each bit is worth twice the one to its right: 1, 2, 4, 8, 16 and so on. Switch bits on and off, count up and watch the carry ripple along, convert to decimal and hexadecimal, and see how computers store negative numbers.
Learning goals
- Explain that binary is a base 2 number system using only the digits 0 and 1
- Convert between binary and decimal numbers up to 8 bits
- Count in binary and explain how carrying works
- Work out the largest number that can be stored in a given number of bits
- Convert binary to hexadecimal and describe overflow and two's complement
How to use it
- 1With 4 bits, switch on one bit at a time. Write down the value of each bit. What pattern do you notice?
- 2Make the numbers 5, 9 and 15 with 4 bits. Which bits did you use?
- 3Press +1 again and again from 0. Which bit changes every time? Which bit changes least often?
- 4Count up to 15 with 4 bits and press +1 once more. What happens, and why?
- 5Switch to 8 bits. What is the largest number you can make? Check it against 2⁸ - 1.
- 6Switch on negative numbers. What is the value of the left bit now? Make -1 and -128.
- 7Choose Make the number and solve five targets. Try starting from the biggest bit.
The model
Assumptions
- Bits are written with the most significant bit on the left, as in ordinary numbers.
- Unsigned numbers run from 0 to 2ⁿ - 1. With negative numbers switched on, two's complement is used and the left bit is worth -2ⁿ⁻¹.
- Adding 1 to the largest value wraps round to the smallest, as real fixed-width computer arithmetic does. This is called overflow.
- Challenge numbers come from a fixed sequence, so every class sees the same targets in the same order.
Try this in class
- Q1Convert 10110 from binary to decimal.
- Q2Convert 45 from decimal to binary using 8 bits.
- Q3How many bits are needed to store numbers up to 1000?
- Q4Why does a binary number that ends in 1 always stand for an odd number?
- Q5In 8-bit two's complement, what is 1111 1110? Explain how you know.
Frequently asked questions
Why do computers use binary instead of decimal?
An electronic switch is easy to make reliable when it only needs two states, off and on. Telling apart ten different voltage levels for decimal digits would be much harder and more error-prone.
What is a byte?
A byte is 8 bits. It can store 256 different values, from 0 to 255, or one character of plain English text.
Why is hexadecimal useful?
Long binary numbers are hard to read. Because 16 = 2⁴, every group of four bits becomes exactly one hexadecimal digit, so programmers use hexadecimal as a short way of writing binary, for example in colour codes like #FF8800.