Understanding the binary addition calculator — concept and principle
This calculator adds two binary numbers column by column, shows the carry produced by every column and, for a fixed register width, checks for unsigned and signed (two's complement) overflow. It is a handy companion for computer science courses, digital electronics and low-level programming.
How it is calculated
Column rules: 0 + 0 = 0; 0 + 1 = 1; 1 + 1 = 0 carry 1; 1 + 1 + 1 = 1 carry 1
Sum = A + B, shown in binary, decimal and hexadecimal
Kept result = the lowest w bits of the sum for a w-bit register
Unsigned overflow: a carry out of the leftmost column
Signed overflow: both inputs have the same sign bit and the kept result has the opposite sign
- Spaces and underscores in the inputs are ignored.
The principle
Binary addition follows exactly the same idea as decimal addition, but each column can hold only 0 or 1, so 1 + 1 makes 10: write 0 and carry 1. A real processor has registers with a fixed number of bits. If the true sum needs one more bit, that bit is lost, which is unsigned overflow. In two's complement, the leftmost bit means negative, so the same bits can also be read as signed numbers. A carry out of the top bit is then normal, but adding two positives that give a negative, or two negatives that give a positive, means the result does not fit: signed overflow.
Worked example
Default inputs: 1011 0110 + 0111 1011, 8-bit register.
- In decimal: 182 + 123 = 305.
- Adding column by column gives the carries 11111110, a total of 7 carries.
- Full sum = 100110001 (decimal 305, hexadecimal 131).
- Kept in 8 bits: 00110001; the carry out of the top bit is lost, so unsigned overflow occurs.
- As signed numbers: −74 + 123 = 49; the inputs have different signs, so no signed overflow.
How to read the result
Whether an overflow matters depends on how you interpret the bits. For unsigned values, 305 does not fit in 8 bits (maximum 255), so the kept value 49 is wrong. For signed values, −74 + 123 = 49 is correct and fits. Processors set separate flags, usually called carry and overflow, to report these two situations.
Common mistakes
- Forgetting the carry into the next column.
- Treating any carry out of the top bit as a signed error.
- Comparing numbers of different widths without padding with leading zeros.
- Reading a two's complement value as unsigned, or the reverse.
Frequently asked questions
What is 1 + 1 in binary?
10: write 0 and carry 1 to the next column.
What is the difference between carry and overflow?
Carry signals unsigned overflow; the overflow flag signals that a signed result is out of range.
How do I read a negative number in two's complement?
If the top bit is 1, subtract 2^width from its unsigned value; 1011 0110 is 182 − 256 = −74.
Can I add numbers of different lengths?
Yes; the shorter one is padded with leading zeros.
Sources: D. Tarnoff, Computer Organization and Design Fundamentals (East Tennessee State University), Chapter 3 "Binary Math and Signed Representations"