4.3 - Binary Numbers & Conversion
Introduction to binary numbers
Computers process and store all data using binary, which consists only of the digits 0 and 1. Every piece of information, from text to images, is converted into binary for the computer to handle.
Comparing binary to decimal
The decimal system, also known as base-10 or denary, is the everyday number system that uses ten digits: 0 through 9. In decimal, place values increase by powers of 10 from right to left, such as 1, 10, 100, and 1000.
Binary, known as base-2, uses only two digits: 0 and 1. Its place values increase by powers of 2 from right to left, such as 1, 2, 4, 8, 16, 32, 64, and 128.
Binary equivalents of decimal numbers 0 to 15
Here are the binary representations for decimal numbers from 0 to 15, shown as 4-bit values for consistency:
| Decimal | Binary |
|---|---|
| 0 | 0000 |
| 1 | 0001 |
| 2 | 0010 |
| 3 | 0011 |
| 4 | 0100 |
| 5 | 0101 |
| 6 | 0110 |
| 7 | 0111 |
| 8 | 1000 |
| 9 | 1001 |
| 10 | 1010 |
| 11 | 1011 |
| 12 | 1100 |
| 13 | 1101 |
| 14 | 1110 |
| 15 | 1111 |
These show how binary builds up using powers of 2, similar to how decimal uses powers of 10.
Converting binary to decimal
To convert a binary number to decimal, identify the place values (powers of 2) and add up those where the binary digit is 1. This method works for any length of binary number, such as 4-bit or 8-bit.
Steps for binary to decimal conversion
- Write the binary number from left to right, assigning powers of 2 starting from the highest on the left (e.g., for 8 bits: 128, 64, 32, 16, 8, 4, 2, 1).
- For each position with a 1, note the corresponding power of 2.
- Add these values together to get the decimal equivalent.
You can use a table to organise this:
| Place value | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
|---|---|---|---|---|---|---|---|---|
| Binary digit |
We would then fill in the binary digits and sum the place values with 1s.
Worked example - Converting binary to decimal
Convert the 8-bit binary number 1010 1100 to decimal.
Step 1: Set up the table
Assign place values and insert the binary digits:
| Place value | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
|---|---|---|---|---|---|---|---|---|
| Binary digit | 1 | 0 | 1 | 0 | 1 | 1 | 0 | 0 |
Step 2: Identify values with 1s
The positions with 1s are: 128, 32, 8, and 4.
Step 3: Add the values
128 + 32 + 8 + 4 = 172
Step 4: Result
The binary number 1010 1100 equals 172 in decimal.
Converting decimal to binary
To convert a decimal number to binary, subtract the largest possible powers of 2 from the number without going negative, placing a 1 in those positions. This is often done using a table for an 8-bit binary number.
Steps for decimal to binary conversion
- Set up a table with powers of 2 in the top row, starting from 128 down to 1 for 8 bits.
- Start with the decimal number as your running total.
- From left to right, if the power of 2 is less than or equal to the running total, subtract it and place a 1 in that position; otherwise, place a 0.
- Update the running total after each subtraction.
- Continue until the running total is 0, then read the binary number from the bottom row.
Worked example - Converting decimal to binary
Convert the decimal number 93 to an 8-bit binary number.
Step 1: Set up the table
Use powers of 2:
| 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
|---|
Running total starts at 93.
Step 2: Subtract and assign digits
- 128 > 93: 0 (running total = 93)
- 64 ≤ 93: 93 - 64 = 29, so 1
- 32 > 29: 0
- 16 ≤ 29: 29 - 16 = 13, so 1
- 8 ≤ 13: 13 - 8 = 5, so 1
- 4 ≤ 5: 5 - 4 = 1, so 1
- 2 > 1: 0
- 1 ≤ 1: 1 - 1 = 0, so 1
Step 3: Complete the table
| 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
|---|---|---|---|---|---|---|---|
| 0 | 1 | 0 | 1 | 1 | 1 | 0 | 1 |
Step 4: Result
The binary number is 0101 1101, which represents 93 in decimal.
Adding binary numbers
Binary addition follows similar rules to decimal addition but uses only 0 and 1. You add column by column from right to left, carrying over when the sum is 2 or more (since binary can't have a 2).
Rules for binary addition
- 0 + 0 = 0
- 1 + 0 = 1
- 1 + 1 = 10 (write 0, carry 1)
- 1 + 1 + 1 = 11 (write 1, carry 1)
These rules prevent any digit higher than 1 in the result.
Steps for column addition in binary
- Align the binary numbers in columns, starting from the right.
- Add the digits in each column, including any carry from the previous column.
- Write the result (0 or 1) and carry over any 1 to the next column if the sum is 2 or 3.
- Continue until all columns are added.
Worked example - Adding binary numbers
Add the 4-bit binary numbers 1011 and 0101.
Step 1: Set up the columns
Step 2: Add from right to left
- Column 1 (right): 1 + 1 = 10 (write 0, carry 1)
- Column 2: 1 + 0 + carry 1 = 10 (write 0, carry 1)
- Column 3: 0 + 1 + carry 1 = 10 (write 0, carry 1)
- Column 4: 1 + 0 + carry 1 = 10 (write 0, carry 1 to a new column if needed, but here it's the end)
Step 3: Write the result
The sum is 10000 (which is 16 in decimal, and 11 + 5 = 16 checks out).
Step 4: Result
Binary addition ensures the result stays in base-2, with carries handling sums over 1.