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, binary subtraction using two's complement, overflow, and bit shifting (logical and arithmetic shifts). These are core skills for the OCR H446 specification.
Binary addition follows the same rules as denary addition, but with only two digits (0 and 1).
| A | B | Sum | Carry |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 1 |
When both bits are 1, the sum is 0 and the carry is 1 (just like 1+1=2 in denary, which is "10" in binary).
If there is also a carry-in of 1: 1 + 1 + 1 = 1 with carry 1.
Carry: 1 1 1 1 1 1
0 1 1 0 1 0 1 1 (107)
+ 0 0 1 1 0 1 0 1 ( 53)
─────────────────
1 0 1 0 0 0 0 0 (160)
Verification: 107 + 53 = 160. Correct.
Carry: 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 (255)
+ 0 0 0 0 0 0 0 1 ( 1)
─────────────────
1 0 0 0 0 0 0 0 0 (256)
This result requires 9 bits. If we are limited to 8 bits, this is an overflow.
Overflow occurs when the result of a calculation exceeds the maximum value that can be stored in the available number of bits.
| Bits | Unsigned Range | Max Value |
|---|---|---|
| 8 | 0 to 255 | 255 |
| 16 | 0 to 65,535 | 65,535 |
| 32 | 0 to 4,294,967,295 | ~4.29 billion |
For unsigned 8-bit numbers, overflow occurs if the result exceeds 255 (i.e., if there is a carry out of the most significant bit).
For signed two's complement numbers, overflow occurs when adding two positive numbers gives a negative result, or adding two negative numbers gives a positive result.
Exam Tip: When performing binary addition in an exam, always check whether the result fits within the given number of bits. If a carry is produced beyond the most significant bit, state that overflow has occurred and explain the consequence.
Binary subtraction can be performed by adding the two's complement of the number being subtracted.
A - B = A + (-B)
To find the two's complement (negative) of B:
Step 1: Find two's complement of 01001011
Actually let us work step by step:
Step 2: Add A + (-B)
1 0 1 1 0 1 0 0 (180)
+ 1 0 1 1 0 1 0 1 (-75 in two's complement)
─────────────────
1 0 1 1 0 1 0 0 1
Discard the carry (9th bit): result = 01101001 = 105
Verification: 180 - 75 = 105. Correct.
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.