Menu Close

Binary Adders Explained: How Computers Add Binary Numbers

Posted in Computer Architecture

Computers perform billions of calculations every second.Binary Adders Explained: How Computers Add Binary Numbers

They add numbers, calculate memory addresses, update counters, compare values, and execute instructions.

But deep inside the processor, there is no decimal arithmetic.

The hardware works with bits:

0
1

So how can a CPU add two numbers together?

The answer begins with one of the most fundamental circuits in digital electronics:

the binary adder.

A binary adder is built from logic gates.

Those logic gates can be combined into a half adder, then a full adder, and finally into circuits capable of adding 8-bit, 32-bit, or 64-bit numbers.

In this tutorial, we will follow that path step by step.

1. Binary Addition

Before building an adder circuit, we first need to understand binary addition itself.

There are only four basic possibilities:

0 + 0 = 0
0 + 1 = 1
1 + 0 = 1
1 + 1 = 10

The last case is the important one.

In binary:

1 + 1 = 10

The result contains two bits.

The right bit is the sum:

0

The left bit is the carry:

1

This is similar to decimal addition.

For example:

9 + 5 = 14

We write 4 in the current decimal position and carry 1 into the next position.

Binary arithmetic works in the same basic way.

2. The Half Adder

The simplest binary adder is called a half adder.

It adds two one-bit values:

A
B

and produces two outputs:

Sum
Carry

The truth table is:

A B Sum Carry
0 0 0 0
0 1 1 0
1 0 1 0
1 1 0 1

Now look at the Sum column:

0 XOR 0 = 0
0 XOR 1 = 1
1 XOR 0 = 1
1 XOR 1 = 0

So:

Sum = A XOR B

Now look at Carry.

Carry becomes 1 only when both A and B are 1.

That is exactly an AND operation:

Carry = A AND B

Therefore, a half adder requires only two logic gates:

A ─────┐
       XOR ───── Sum
B ─────┘


A ─────┐
       AND ───── Carry
B ─────┘

This is our first real arithmetic circuit.

3. Why the Half Adder Is Not Enough

The half adder can add two bits.

But there is a problem.

When we add multi-bit binary numbers, a bit position may receive a carry from the previous position.

Consider:

  01
+ 01
----
  10

The rightmost bits calculate:

1 + 1

which produces:

Sum   = 0
Carry = 1

That carry must now be added into the next column.

So the next stage may need three inputs:

A
B
Carry In

A half adder cannot handle this third input.

We need a full adder.

4. The Full Adder

A full adder adds three one-bit inputs:

A
B
Cin

Cin means Carry In.

It produces two outputs:

Sum
Cout

Cout means Carry Out.

The complete truth table is:

A B Cin Sum Cout
0 0 0 0 0
0 0 1 1 0
0 1 0 1 0
0 1 1 0 1
1 0 0 1 0
1 0 1 0 1
1 1 0 0 1
1 1 1 1 1

The Sum output is:

Sum = A XOR B XOR Cin

The Carry Out can be written as:

Cout = AB + Cin(A XOR B)

An equivalent form is:

Cout = AB + ACin + BCin

The most important idea is simple:

Carry Out becomes 1 whenever at least two of the three input bits are 1.

5. Building a Full Adder from Two Half Adders

A full adder can be constructed from:

2 Half Adders
+
1 OR Gate

First, A and B enter the first half adder.

A ─────┐
       Half Adder ───── S1
B ─────┘                C1

It generates:

S1 = A XOR B

C1 = A AND B

Then S1 and Cin enter the second half adder:

S1 ────┐
       Half Adder ───── Sum
Cin ───┘                C2

Finally, the two carry signals are combined with an OR gate:

C1 ────┐
       OR ───── Cout
C2 ────┘

The complete logic is therefore:

A ───────┐
         XOR ─── S1 ─────┐
B ───────┘                XOR ───── Sum
                          │
Cin ──────────────────────┘


A ───────┐
         AND ─── C1 ─────┐
B ───────┘                │
                          OR ───── Cout
S1 ──────┐                │
         AND ─── C2 ─────┘
Cin ─────┘

This small circuit is one of the fundamental building blocks of computer arithmetic.

6. Carry Connects the Bit Positions

Now we can begin adding multi-bit numbers.

Suppose we want to calculate:

  0101
+ 0011

In decimal, this is:

5 + 3

We begin with the least significant bit on the right.

Bit 0

1 + 1 = 10

So:

Sum   = 0
Carry = 1

Bit 1

The next column must include the incoming carry:

0 + 1 + 1 = 10

Again:

Sum   = 0
Carry = 1

Bit 2

1 + 0 + 1 = 10

So:

Sum   = 0
Carry = 1

Bit 3

0 + 0 + 1 = 1

The complete result is:

  0101
+ 0011
------
  1000

Therefore:

5 + 3 = 8

7. The Multi-Bit Adder

A multi-bit binary adder can be created by connecting several full adders together.

For a 4-bit adder:

A0 B0       A1 B1       A2 B2       A3 B3
 ↓  ↓        ↓  ↓        ↓  ↓        ↓  ↓
[FA0] ────> [FA1] ────> [FA2] ────> [FA3]
 ↓            ↓            ↓            ↓
S0           S1           S2           S3

        Carry → Carry → Carry

Each full adder handles one bit position.

The carry output of one stage becomes the carry input of the next stage:

Cout0 → Cin1
Cout1 → Cin2
Cout2 → Cin3

Because the carry moves from one stage to the next, this architecture is called a:

Ripple Carry Adder

The carry effectively ripples through the circuit.

8. From 4 Bits to 32 or 64 Bits

The same idea can be extended to larger numbers.

An 8-bit adder handles eight bit positions.

A 32-bit adder can conceptually add:

A31 ... A3 A2 A1 A0
+
B31 ... B3 B2 B1 B0

and produce:

S31 ... S3 S2 S1 S0

A 64-bit adder follows the same basic principle.

This demonstrates an important idea in digital design:

Large arithmetic circuits can be constructed by combining smaller circuits.

A full adder handles one bit.

Multiple bit stages together can handle an entire binary number.

9. The Problem with Ripple Carry

The ripple carry adder is simple and easy to understand.

But it has an important weakness.

Each stage may need to wait for the carry generated by the previous stage.

For example, in a 32-bit addition, a carry may need to propagate through many bit positions:

Bit 0
  ↓
Bit 1
  ↓
Bit 2
  ↓
...
  ↓
Bit 31

This propagation takes time.

The longer the carry chain becomes, the larger the worst-case delay can become.

For this reason, high-performance processors may use faster adder architectures such as:

Carry Lookahead Adders
Carry Select Adders
Prefix Adders

These designs reduce carry propagation delay.

However, they are optimizations of the same fundamental binary arithmetic.

Understanding the ripple carry adder first makes these faster designs much easier to understand later.

10. How the Same Adder Can Perform Subtraction

This is where two’s complement becomes extremely important.

Suppose we want to calculate:

A - B

Instead of creating a completely separate subtraction circuit, we can rewrite subtraction as addition:

A - B = A + (-B)

In two’s complement:

-B = NOT B + 1

Therefore:

A - B = A + NOT B + 1

This means the same binary adder can also perform subtraction.

11. Example: 7 – 3

Using four bits:

7 = 0111
3 = 0011

We want to calculate:

7 - 3

First, create the two’s complement representation of -3.

Start with:

0011

Invert all bits:

1100

Add 1:

1101

So:

-3 = 1101

Now add:

  0111
+ 1101
------
1 0100

Because we are working with four-bit values, the carry beyond the most significant bit is discarded.

The four-bit result is:

0100

which is decimal 4.

Therefore:

7 - 3 = 4

The same binary adder has performed subtraction.

12. Building an Adder/Subtractor

Hardware can implement addition and subtraction using the same circuit.

Suppose we introduce a control signal called:

SUB

When:

SUB = 0

the circuit performs:

A + B

When:

SUB = 1

the circuit performs:

A - B

The key trick is to place XOR gates on the B inputs.

Each B bit goes through:

B XOR SUB

When SUB is 0:

B XOR 0 = B

So B passes through unchanged.

The adder calculates:

A + B

But when SUB is 1:

B XOR 1 = NOT B

So every bit of B is inverted.

At the same time, SUB can be connected to the Carry In of the least significant full adder:

Cin = SUB

Therefore, when SUB is 1:

Cin = 1

The circuit now calculates:

A + NOT B + 1

which is exactly:

A - B

So a single control signal can transform the same hardware between addition and subtraction.

This is one of the most useful consequences of two’s complement representation.

13. Carry and Overflow Are Not the Same

Carry and signed overflow are related to arithmetic, but they are not the same thing.

Consider unsigned four-bit addition:

1111 + 0001

This is:

15 + 1

The result is:

1 0000

The extra bit is a carry out.

For unsigned arithmetic, the carry indicates that the result requires more than four bits.

Signed two’s complement arithmetic uses a different concept called overflow.

In four-bit signed arithmetic:

0111 = +7

Now calculate:

  0111
+ 0001
------
  1000

But in four-bit two’s complement:

1000 = -8

A positive value plus another positive value produced a negative result.

That means signed overflow occurred.

Therefore:

Carry is not the same as signed overflow.

A processor can track these conditions separately.

14. The Adder Inside the ALU

A binary adder is normally part of a larger CPU circuit called the:

Arithmetic Logic Unit, or ALU.

An ALU may perform operations such as:

ADD
SUB
AND
OR
XOR
SHIFT
COMPARE

For an ADD operation, the processor can send two register values into the ALU:

Register A
    ↓
   ALU
    ↑
Register B

Inside the ALU, the adder calculates the result.

The result can then be written back into the register file.

Register File
     ↓
    ALU
  [Adder]
     ↓
Register File

Now the binary adder is no longer an isolated digital circuit.

It has become part of the CPU datapath.

15. From an ADD Instruction to Logic Gates

This connects the binary adder directly to CPU instructions.

Suppose a processor executes an instruction conceptually similar to:

ADD R1, R2

At the software level, we see an assembly instruction.

But inside the processor, that instruction causes hardware to perform a sequence of operations:

Read registers
      ↓
Send operands to the ALU
      ↓
Select the ADD operation
      ↓
Binary adder calculates the result
      ↓
Write the result back

Deep inside the binary adder are the same basic logic operations we started with:

XOR
AND
OR

So we can trace an ADD instruction through several layers of the computer:

ADD Instruction
      ↓
Control Unit
      ↓
ALU
      ↓
Binary Adder
      ↓
Full Adders
      ↓
XOR / AND / OR Gates
      ↓
Transistors

This is the connection between software instructions and physical digital hardware.

Conclusion

A binary adder demonstrates one of the most important ideas in computer architecture:

Complex computation can be built from extremely simple logic.

A half adder adds two bits:

A + B

A full adder handles three inputs:

A + B + Carry In

Multiple full adders can be connected to form a multi-bit adder.

Carry signals connect one bit position to the next.

Two’s complement allows the same adder to perform subtraction:

A - B
=
A + NOT B + 1

And inside a CPU, the binary adder becomes one of the most important components of the ALU.

So when software executes an instruction such as:

ADD

there is an entire hardware chain underneath it:

Instruction
↓
Control Unit
↓
ALU
↓
Binary Adder
↓
Logic Gates
↓
Transistors

That is how a computer turns zeros and ones into arithmetic.

Leave a Reply

Your email address will not be published. Required fields are marked *