1.1 Data Representation

Show All Section Notes

Binary Addition and Overflow

1. The Four Rules of Binary Addition

Binary addition follows the same logic as denary addition (carrying values to the next column), but you only have two digits to work with.

$0 + 0 = 0$
$0 + 1 = 1$
$1 + 1 = 10$
(0 carry 1)
$1 + 1 + 1 = 11$
(1 carry 1)

2. Addition Example

When adding binary numbers, always start from the Right (the Least Significant Bit).

 111     (Carries)
 01101010 (106)
+00011100 (28)
10000110 (134)

3. Overflow Errors

In IGCSE Computer Science, we usually work with 8-bit registers. An 8-bit register can store a maximum value of 255 ($11111111$).

Definition: An Overflow Error occurs when the result of a binary addition exceeds the maximum capacity of the register (e.g., the result needs 9 bits but only 8 are available).

Example of Overflow:

Attempting to add $150 + 150$ in an 8-bit register:

11       
  10010110 (150)
+ 10010110 (150)
100101100 (300)

The 9th bit (highlighted in red) has nowhere to go. The CPU simply drops it.

4. Consequences of Overflow

  • Data Loss: The computer "ignores" the extra bit, leading to an mathematically incorrect result (e.g., $150+150$ might appear to equal $44$).
  • System Crashes: In some cases, an unexpected overflow can cause a program to crash or behave unpredictably.
  • Security Risks: Hackers sometimes use "Buffer Overflows" to gain control of a system by forcing data into memory it shouldn't access.

5. Logical Binary Shifts

While not addition, shifting bits is a form of arithmetic often linked to this topic:

  • Left Shift ($\ll$): Multiplies the number by 2 for every place shifted.
  • Right Shift ($\gg$): Divides the number by 2 (integer division) for every place shifted.
1 + 1 is 10, not 2!