You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
This lesson covers binary addition and logical binary shifts, both required for OCR J277 Section 2.6. You must be able to add two 8-bit binary numbers and understand the effect of left and right shifts.
Binary addition follows four simple rules:
| 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) |
There is one additional rule when a carry is involved:
| Addition | Result | Carry |
|---|---|---|
| 1 + 1 + 1 (carry) | 1 | 1 |
Add 01101010 + 00110101
Work from right to left, just like denary addition:
| Row | b8 | b7 | b6 | b5 | b4 | b3 | b2 | b1 | Decimal |
|---|---|---|---|---|---|---|---|---|---|
| Carry | 1 | 1 | 1 | 1 | 1 | ||||
| 0 | 1 | 1 | 0 | 1 | 0 | 1 | 0 | 106 | |
| + | 0 | 0 | 1 | 1 | 0 | 1 | 0 | 1 | 53 |
| Sum | 1 | 0 | 0 | 1 | 1 | 1 | 1 | 1 | 159 |
Check: 106 + 53 = 159. Converting 10011111 to denary: 128 + 16 + 8 + 4 + 2 + 1 = 159. Correct!
OCR Exam Tip: Always show your carry digits above the calculation. This is how examiners verify your working, and you may get method marks even if the final answer is wrong.
Overflow occurs when the result of a binary addition is too large to be stored in the available number of bits. For 8-bit numbers, the maximum value is 255 (11111111).
Example of overflow:
| Row | ov | b8 | b7 | b6 | b5 | b4 | b3 | b2 | b1 | Decimal |
|---|---|---|---|---|---|---|---|---|---|---|
| 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 192 | ||
| + | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 128 | |
| Sum | 1 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 320 (9 bits!) |
The result requires 9 bits, but only 8 bits are available. The extra bit is lost, and the stored value would be 01000000 (64), which is incorrect. This is an overflow error.
OCR Exam Tip: If the exam asks you to "explain what happens" when overflow occurs, state that the result exceeds the maximum value that can be stored in the available bits, causing an incorrect value to be stored.
flowchart TD
A[Two 8-bit binary numbers] --> B[Add column by column right to left]
B --> C{1 + 1?}
C -->|Yes| D[Write 0, carry 1]
C -->|No| E[Write sum, carry 0]
D --> F[Continue to next column]
E --> F
F --> G{Result > 8 bits?}
G -->|Yes| H[Overflow - extra bit lost]
G -->|No| I[Valid 8-bit result]
I --> J[Optional logical shift]
J --> K[Left shift = x2 per position]
J --> L[Right shift = integer divide by 2]
K --> M[New 8-bit value, 0s fill the right]
L --> N[New 8-bit value, 0s fill the left]
A binary shift moves all the bits in a binary number to the left or right by a specified number of positions. Bits shifted off the end are lost, and empty positions are filled with 0s.
A left shift moves all bits to the left. Each left shift by 1 position multiplies the value by 2.
Example: Left shift 00010110 (22) by 1 position
| Step | b8 | b7 | b6 | b5 | b4 | b3 | b2 | b1 | Decimal |
|---|---|---|---|---|---|---|---|---|---|
| Before | 0 | 0 | 0 | 1 | 0 | 1 | 1 | 0 | 22 |
| After | 0 | 0 | 1 | 0 | 1 | 1 | 0 | 0 | 44 |
The leftmost bit (0) is lost, and a 0 is added on the right. The value doubled from 22 to 44.
Left shift by 2 positions multiplies by 4 (2 x 2):
| Step | b8 | b7 | b6 | b5 | b4 | b3 | b2 | b1 | Decimal |
|---|---|---|---|---|---|---|---|---|---|
| Before | 0 | 0 | 0 | 1 | 0 | 1 | 1 | 0 | 22 |
| After | 0 | 1 | 0 | 1 | 1 | 0 | 0 | 0 | 88 |
22 x 4 = 88. Correct!
A right shift moves all bits to the right. Each right shift by 1 position performs integer division by 2 (the result is rounded down).
Example: Right shift 00010110 (22) by 1 position
| Step | b8 | b7 | b6 | b5 | b4 | b3 | b2 | b1 | Decimal |
|---|---|---|---|---|---|---|---|---|---|
| Before | 0 | 0 | 0 | 1 | 0 | 1 | 1 | 0 | 22 |
| After | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 1 | 11 |
The rightmost bit (0) is lost, and a 0 is added on the left. The value halved from 22 to 11.
Right shift 00010111 (23) by 1 position:
| Step | b8 | b7 | b6 | b5 | b4 | b3 | b2 | b1 | Decimal |
|---|---|---|---|---|---|---|---|---|---|
| Before | 0 | 0 | 0 | 1 | 0 | 1 | 1 | 1 | 23 |
| After | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 1 | 11 |
23 / 2 = 11.5, but since we lose the rightmost bit, the result is 11 (integer division, rounded down).
| Shift | Direction | Positions | Effect on value |
|---|---|---|---|
| Left shift by 1 | Left | 1 | Multiply by 2 |
| Left shift by 2 | Left | 2 | Multiply by 4 |
| Left shift by 3 | Left | 3 | Multiply by 8 |
| Right shift by 1 | Right | 1 | Integer divide by 2 |
| Right shift by 2 | Right | 2 | Integer divide by 4 |
| Right shift by 3 | Right | 3 | Integer divide by 8 |
OCR Exam Tip: If a shift question asks for the denary value before and after, convert both binary numbers to denary and verify that the multiplication/division is correct.
Left shifts can also cause overflow if significant bits (1s) are shifted off the left end:
| Step | b8 | b7 | b6 | b5 | b4 | b3 | b2 | b1 | Decimal | Note |
|---|---|---|---|---|---|---|---|---|---|---|
| Before | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 192 | |
| Left 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 128 | lost a 1 bit! |
192 x 2 = 384, which cannot fit in 8 bits. The result is 128, which is incorrect.
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.