Overview
This lecture explains binary addition, introduces two's complement for representing negative binary numbers, and discusses overflow detection—key foundations for building an 8-bit computer's arithmetic unit.
Binary Addition
- Binary addition works similarly to decimal: add digit by digit, starting from the rightmost column.
- 1 + 1 in binary equals 10 (2 in decimal), requiring you to write 0 and carry over 1.
- Binary numbers are added column-wise; carried values move to the next column left.
- When adding, if you sum more than one digit per column, the carry strategy is repeated.
- Example: 101 (5) + 010 (2) = 111 (7); 101 (5) + 011 (3) = 1000 (8) after carries.
Storing Binary Numbers & Bit Width
- Computers store numbers in fixed-width groups called bits (e.g., 8 bits = 1 byte).
- The number of bits determines the range of values that can be stored.
- Larger bit-widths (e.g., 32, 64) allow for higher positive and negative number ranges.
Representing Negative Numbers: Two's Complement
- Two's complement allows binary numbers to represent negative values.
- To find the two's complement (negative) of a number: invert all bits and add 1.
- The most significant bit (leftmost) is the sign bit (1 = negative, 0 = positive).
- Example: 0001 (1) → invert (1110) + 1 = 1111 (−1 in two's complement with 4 bits).
Binary Subtraction Using Two's Complement
- Subtraction can be performed by adding a negative number in two's complement form.
- Example: 1 + (−1) in two’s complement gives 0000 (0).
Overflow Detection in Two's Complement
- Overflow happens if a calculation exceeds the highest positive or lowest negative value storable in the given bit-width.
- Check for overflow by comparing the carry into and out of the sign bit position; if they differ, overflow has occurred.
Examples with Two's Complement & Overflow
- Example: 0110 (6) + 0101 (5) in 4 bits gives 1011 (−5), showing overflow (expected 11).
- Validity of the result is checked by comparing the last two carry bits; if they are equal, the result is valid.
Key Terms & Definitions
- Binary Addition — The process of summing binary numbers digit by digit, carrying over when sums reach 2.
- Bit — A binary digit (0 or 1); 8 bits = 1 byte.
- Two's Complement — Method to represent negative binary numbers; invert all bits, add one.
- Overflow — Result of a calculation exceeding storage limits for the chosen bit-width.
Action Items / Next Steps
- Practice binary addition and two’s complement conversions.
- Review overflow detection by checking carry bits in example calculations.
- Prepare for the next lecture on designing a binary adder.