Binary numbers explained: converting and adding
TutorAura guide · Updated
Computers store everything as binary: numbers made of only 0s and 1s, because electronic circuits have two states (off and on). Binary is a base 2 number system. Instead of place values of 1, 10, 100 (powers of 10), binary place values are powers of 2: 1, 2, 4, 8, 16 and so on.
Key takeaways
- Binary place values: 128, 64, 32, 16, 8, 4, 2, 1.
- One bit is a 0 or 1; 8 bits make a byte.
- 8 bits can store 256 values (0 to 255).
- Each hex digit stands for 4 bits.
Binary to decimal
Write the place values over the digits and add the ones under each 1.
| 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
|---|---|---|---|---|---|---|---|
| 1 | 1 | 0 | 0 | 1 | 0 | 0 | 0 |
. So 11001000 in binary is 200.
Smaller example: .
Decimal to binary
Subtract the largest place values that fit, from the left:
13: 8 fits (leaves 5), 4 fits (leaves 1), 2 doesn't, 1 fits. So .
Or keep dividing by 2 and read the remainders from the bottom up: r 1, r 0, r 1, r 1, giving 1101.
Binary addition
The rules: , , (write 0, carry 1), (write 1, carry 1).
(that's ).
If the answer needs more bits than are available, an overflow error occurs: in 4 bits, 10001 doesn't fit.
Bits, bytes and storage
- A bit is a single binary digit.
- A nibble is 4 bits; a byte is 8 bits.
- With bits you can represent different values: 8 bits give values, from 0 to 255.
File sizes build up from bytes: kilobytes, megabytes, gigabytes. In GCSE Computer Science, a kilobyte is 1,000 bytes and a kibibyte is 1,024.
Hexadecimal
Hexadecimal (base 16) uses 0 to 9 then A to F (A = 10, F = 15). Each hex digit represents exactly 4 bits, so hex is a short way to write binary.
- 200 in binary is 1100 1000. 1100 = 12 = C and 1000 = 8, so 200 = C8 in hex.
- FF in hex = .
Programmers use hex for colours (#FF0000 is red) and memory addresses.
Common mistakes
- Writing place values in the wrong order (the largest is on the left).
- Forgetting to carry in addition.
- Thinking 8 bits store up to 256 (the largest is 255, because 0 is one of the 256 values).
For more computing help, see our guide to learning Python and our computer science tutor.
Practice questions
- Convert 10110 to decimal.
- Convert 45 to binary.
- Add 0101 and 0011 in binary.
- Convert the hex number 3A to decimal.
Answers: 1. . 2. 101101 (). 3. 1000 (that's ). 4. .
How text and images are stored
- Text: each character has a binary code. ASCII uses 7 bits, giving characters; Unicode uses more bits to cover characters from every writing system and emoji.
- Images: a picture is a grid of pixels, and each pixel's colour is stored as a binary number. With a colour depth of 1 bit there are 2 colours; with 8 bits, . More bits mean more colours and a bigger file.
Frequently asked questions
How do you convert binary to decimal?
Write the place values (1, 2, 4, 8, …) from right to left above the digits and add the place values under each 1.
Why do computers use binary?
Because their circuits have two states, on and off, which map to 1 and 0.
How many values can a byte store?
256 different values (0 to 255), because a byte has 8 bits and 2⁸ = 256.
Sources
Keep reading
An AI coding tutor for school computer science
Understand error messages, debug your own code and learn computer science concepts, step by step.
How to learn Python as a student: a beginner's plan
Core concepts in a sensible order, small programs every day, reading errors, and a first project.
Computer science homework help, one step at a time
Python, algorithms, binary and theory: find bugs and understand the code yourself.
Online scientific calculator
Trig, logs, powers, roots, factorials and standard form, with a history you can reuse.