Binary addition is the mathematical process of summing two base-2 numbers using four fundamental rules: 0+0=0, 0+1=1, 1+0=1, and 1+1=10 (0 with a carry of 1). In physical circuits, these rules dictate the exact gate-level wiring of the Arithmetic Logic Unit (ALU) inside microcontrollers like the ATmega328P or ESP32, determining how XOR and AND gates are cascaded to process data. Beginners frequently confuse binary addition with Boolean OR logic; in binary math, 1 + 1 equals 10 (decimal 2), whereas in Boolean logic, 1 OR 1 equals 1. Understanding this distinction is critical when writing embedded C++ or designing FPGA logic blocks.

The Core Rules for Adding Binary Numbers and Full-Adder Logic

While the four basic rules of binary addition are simple on paper, physical silicon cannot natively process a "carry" without a dedicated circuit path. This is why engineers use the Full Adder topology. A full adder takes three inputs—the two bits being added (A and B) plus a Carry-In (Cin) from the previous less-significant bit—and produces a Sum and a Carry-Out (Cout).

Full Adder Truth Table (Base-2 Addition Logic)
Input A Input B Carry-In (Cin) Sum (A ⊕ B ⊕ Cin) Carry-Out (Cout) Decimal Equivalent
000000 + 0 + 0 = 0
001100 + 0 + 1 = 1
010100 + 1 + 0 = 1
011010 + 1 + 1 = 2
100101 + 0 + 0 = 1
101011 + 0 + 1 = 2
110011 + 1 + 0 = 2
111111 + 1 + 1 = 3

As detailed in standard digital design texts like All About Circuits, the Sum output is generated using a cascaded XOR gate configuration (Sum = A ⊕ B ⊕ Cin), while the Carry-Out relies on a combination of AND and OR gates (Cout = (A AND B) OR (Cin AND (A ⊕ B))). This physical separation of Sum and Carry is what allows 32-bit and 64-bit processors to chain these blocks together.

Worked Numeric Example: 4-Bit Ripple Carry Addition

To see the rules for adding binary numbers in action, let us add two 4-bit numbers: 1011 (decimal 11) and 1101 (decimal 13). We expect a decimal result of 24, which is 11000 in binary.

Setup:
  1011 (A)
+ 1101 (B)
-------

Bit 0 (Least Significant Bit - LSB):
A=1, B=1, Cin=0. According to the rules, 1+1=10.
Sum = 0, Carry-Out = 1

Bit 1:
A=1, B=0, Cin=1 (from Bit 0). We are adding 1+0+1.
Sum = 0, Carry-Out = 1

Bit 2:
A=0, B=1, Cin=1 (from Bit 1). We are adding 0+1+1.
Sum = 0, Carry-Out = 1

Bit 3 (Most Significant Bit of the inputs):
A=1, B=1, Cin=1 (from Bit 2). We are adding 1+1+1.
Sum = 1, Carry-Out = 1

Bit 4 (Final Carry-Out):
The final Carry-Out from Bit 3 becomes the 5th bit of our result.
Final Bit = 1

Final Result: Reading from Bit 4 down to Bit 0, we get 11000. Converting 11000 to decimal yields (1×16) + (1×8) + (0×4) + (0×2) + (0×1) = 24. The math holds up perfectly.

Where You Meet This in Practice (Circuits & Code)

You will not manually calculate binary addition when wiring a relay, but the rules govern the behavior of the components you use every day on the bench.

1. Microcontroller ALUs and Overflow Flags

When you write int c = a + b; on an Arduino Uno, the ATmega328P microcontroller routes those variables through its hardware ALU. If you add two 8-bit numbers (e.g., 200 + 100), the mathematical result is 300. However, an 8-bit register maxes out at 255. The ALU uses the rules of binary addition, generates a Carry-Out on the 8th bit, and triggers the Carry Flag in the Status Register. If you are writing assembly or highly optimized embedded C, checking this flag is how you detect integer overflow.

2. Shift Registers and I2C Addressing

When configuring an I2C expander like the PCF8574, the base address is often set via hardware pins (e.g., A0, A1, A2). If the base address is 0100000 and you wire A0 and A1 HIGH (adding 011), the I2C controller physically performs binary addition to resolve the final 7-bit address (0100011, or 0x23 in hex). Misunderstanding binary addition here leads to addressing collisions on the I2C bus.

3. FPGA and CPLD Logic Blocks

If you are programming an FPGA using Verilog or VHDL, the synthesis tool will map your + operators directly to Look-Up Tables (LUTs) configured as full adders. According to the Espressif ESP32 Technical Reference Manual, advanced processors use Carry-Lookahead Adders (CLA) rather than simple ripple-carry chains to bypass the propagation delay of waiting for each bit's carry to resolve sequentially.

Common Pitfalls and Troubleshooting Adder Logic

Why does my C++ bitwise code return the wrong sum?

The most common error is using the bitwise OR operator (|) instead of the addition operator (+). In binary math, 1 + 1 = 10 (which is 2 in decimal). In bitwise OR logic, 1 | 1 = 1. If you are trying to add sensor values or increment counters, using | will silently cap your maximum value and destroy the carry bit.

What is propagation delay in a ripple carry adder?

In a basic 32-bit ripple carry adder, Bit 31 cannot calculate its final sum until the carry signal physically propagates through all 30 preceding full-adder gates. At high clock speeds (e.g., 240 MHz on an ESP32), this nanosecond-level gate delay creates a bottleneck. Modern silicon solves this using Carry-Lookahead logic, which generates carries in parallel rather than sequentially.

How do I handle negative numbers in binary addition?

Microcontrollers use Two's Complement representation for signed integers. To add a negative number, the ALU inverts all bits of the positive equivalent and adds 1. The beauty of Two's Complement is that the ALU uses the exact same physical full-adder rules for addition, whether the numbers are positive or negative, eliminating the need for separate subtraction hardware.