You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
Once you understand binary numbers, you need to be able to perform arithmetic operations on them. This lesson covers binary addition and binary shifts, both of which are required for the GCSE Computer Science exam.
Binary addition follows rules similar to denary addition, but with only two digits (0 and 1). The key rules are:
| Addition | Result | Carry |
|---|---|---|
| 0 + 0 | 0 | 0 |
| 0 + 1 | 1 | 0 |
| 1 + 0 | 1 | 0 |
| 1 + 1 | 0 | 1 (carry 1 to the next column) |
| 1 + 1 + 1 | 1 | 1 (carry 1 to the next column) |
The most important rule to remember is: 1 + 1 = 10 in binary (just as 9 + 1 = 10 in denary — you write 0 and carry 1).
Carries: 1 1 1 1 1
0 1 0 0 1 0 1 0 (74 in denary)
+ 0 0 1 1 0 1 0 1 (53 in denary)
-------------------
0 1 1 1 1 1 1 1 (127 in denary)
Check: 74 + 53 = 127. Correct!
Carries: 1 1 1 1 1 1
1 1 0 1 0 1 1 0 (214 in denary)
+ 0 0 1 0 1 0 1 1 (43 in denary)
-------------------
1 0 0 0 0 0 0 0 1 (257 in denary)
Notice this result is 9 bits — it does not fit in 8 bits. This is called an overflow error.
An overflow error occurs when the result of a calculation is too large to be stored in the available number of bits. For an 8-bit unsigned binary number, the maximum value is 255 (11111111). If the result exceeds 255, the 9th bit is lost (or flagged as an error), and the stored value will be incorrect.
Exam Tip: If an exam question asks you to add two 8-bit binary numbers and the result has 9 bits, you must state that an overflow error has occurred. The exam often awards a mark specifically for identifying this.
flowchart TD
A[Binary number] --> B{Shift direction?}
B -->|Left by n| C[Multiply by 2^n]
B -->|Right by n| D[Divide by 2^n]
C --> E{Bit lost off left?}
D --> F{Bit lost off right?}
E -->|Yes| G[Overflow]
E -->|No| H[Result valid]
F -->|Yes| I[Loss of precision]
F -->|No| H
A binary shift moves all the bits in a binary number to the left or to the right by a specified number of positions. Bits shifted beyond the edge of the register are lost, and zeros fill the vacated positions.
A left shift moves all bits to the left. Each position shifted multiplies the number by 2.
Original number: 00010110 (22 in denary)
| Step | Binary | Denary |
|---|---|---|
| Original | 00010110 | 22 |
| Left shift by 1 | 00101100 | 44 |
22 × 2 = 44. Correct!
Original number: 00000101 (5 in denary)
| Step | Binary | Denary |
|---|---|---|
| Original | 00000101 | 5 |
| Left shift by 1 | 00001010 | 10 |
| Left shift by 2 | 00010100 | 20 |
5 × 4 = 20. Correct!
A right shift moves all bits to the right. Each position shifted divides the number by 2 (integer division — any remainder is lost).
Original number: 00101000 (40 in denary)
| Step | Binary | Denary |
|---|---|---|
| Original | 00101000 | 40 |
| Right shift by 1 | 00010100 | 20 |
| Right shift by 2 | 00001010 | 10 |
40 ÷ 4 = 10. Correct!
Original number: 00010011 (19 in denary)
| Step | Binary | Denary |
|---|---|---|
| Original | 00010011 | 19 |
| Right shift by 1 | 00001001 | 9 |
19 ÷ 2 = 9.5, but since we lose the remainder, the result is 9. The least significant bit (the 1) is lost during the shift.
Carries: 1 1
0 0 1 1 0 0 1 1 (51)
+ 0 0 0 1 0 1 0 1 (21)
-------------------
0 1 0 0 1 0 0 0 (72)
Verification: 51 + 21 = 72. The result is 01001000, which fits comfortably in 8 bits, so no overflow has occurred.
Carries: 1 1 1 1 1 1 1
1 0 0 0 0 0 0 1 (129)
+ 0 1 1 1 1 1 1 1 (127)
-------------------
1 0 0 0 0 0 0 0 0 (256)
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.