2 ms·
The trick is binary addition works the same as regular addition, but is so simple that even a silly little logic gate can do it. Think about adding two bits. T
by bigyikes 2y ago
The trick is binary addition works the same as regular addition, but is so simple that even a silly little logic gate can do it.
Think about adding two bits. There are only four possible ways to do it.
0+0=0
0+1=1
1+0=1
1+1=0 (carry 1)
If you squint at the bit patterns in those addition facts, you realize it is actually the truth table for XOR (ignoring the carry). So adding bits A and B is the same as taking A XOR B.
What about carrying the 1? The carry can be represented as an AND: you only carry the 1 if A and B are both 1. So a simple 1-bit adder can be made by combining an AND and a XOR.
Everything becomes simpler when you stop thinking in terms of addition and start thinking in terms of truth tables for bits. Take the truth table for a two bit adder (AB + CD = XY):
A B C D X Y
0 0 0 0 0 0
0 0 0 1 0 1
0 0 1 0 0 1
0 0 1 1 1 0
…
1 1 1 1 1 1
If you learn the basic algorithm for converting a truth table into logic gates, you can represent any bit pattern as gates, including addition operations. Adders are nice because you can basically concatenate them together in a chain to add larger and larger patterns of bits.