Perform binary addition and subtraction
📚 1.1 Data Representation – Binary Arithmetic
Why Binary?
Binary is the language computers speak. Think of it as a series of light switches: 0 = switch off, 1 = switch on. Because a computer can easily detect whether a switch is on or off, it uses only two states to represent all information.
Binary Addition Basics
Adding binary numbers is similar to decimal addition, but the carry rule changes. The truth table for a single column is:
| a | b | carry‑in | sum | carry‑out |
|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 |
| 0 | 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 0 | 1 |
| 1 | 1 | 1 | 1 | 1 |
Step‑by‑Step Example
Add the two binary numbers below:
- Align the numbers by their least‑significant bit (right‑most).
- Start from the right, add each column using the truth table above.
- Write the sum bit and carry the carry‑out to the next column on the left.
- Continue until the leftmost column. If there is a final carry‑out, write it as the new most‑significant bit.
Example: $1011_2 + 1101_2$
| carry‑in | a | b | sum | carry‑out |
|---|---|---|---|---|
| 0 | 1 | 1 | 0 | 1 |
| 1 | 1 | 0 | 0 | 1 |
| 1 | 0 | 1 | 1 | 1 |
| 1 | 1 | 0 | 1 | 1 |
| 1 | 0 | 1 | 1 | 0 |
Reading from left to right, the final result is $11000_2$ (or $24_{10}$). 📈
Binary Subtraction – Borrowing
Subtraction works like borrowing in decimal. The truth table for a single column (including borrow‑in) is:
| a | b | borrow‑in | difference | borrow‑out |
|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 |
| 1 | 0 | 0 | 1 | 0 |
| 0 | 1 | 0 | 1 | 1 |
| 1 | 1 | 0 | 0 | 0 |
| 0 | 1 | 1 | 0 | 1 |
Example: $1100_2 - 101_2$ (align to $0101_2$)
- Start from the rightmost bit.
- If the top bit is smaller than the bottom bit, borrow 1 from the next left column (which becomes 0 after borrowing).
- Compute the difference for that column.
- Continue leftwards.
| borrow‑in | a | b | difference | borrow‑out |
|---|---|---|---|---|
| 0 | 0 | 1 | 1 | 1 |
| 1 | 0 | 0 | 1 | 0 |
| 0 | 1 | 0 | 1 | 0 |
| 0 | 1 | 0 | 1 | 0 |
The final result is $101_2$ (or $5_{10}$). ??
Practice Problems
- Compute $10101_2 + 11010_2$.
- Subtract $10011_2 - 111_2$.
- What is the binary result of $1111_2 + 1_2$? (Hint: think of a carry‑over.)
Quick Recap
- Binary uses only 0 and 1 – like light switches.
- Carry in addition: 1+1=0 with carry‑out 1.
- Borrow in subtraction: if the top bit is 0, borrow 1 from the next left bit.
- Always align numbers to the right before starting.
Keep practising and soon binary arithmetic will feel as natural as adding and subtracting in decimal. Happy computing! 🚀
Revision
Log in to practice.