Implementing Logic Gates in a Spreadsheet

Here are some of the basic logic gates, implemented as spreadsheet formulas.

GateSpreadsheet Formula
ANDAND(A,B)
OROR(A,B)
NOTNOT(B)
NANDNOT(AND(A,B))
NORNOT(OR(A,B))
XOROR(AND(A,NOT(B)),AND(NOT(A),B))
XNORNOT(OR(NOT(OR(A,NOT(OR(A,B)))),NOT(OR(B,NOT(OR(A,B))))))

It is possible to implement any gate using only NOT and OR (NOR), or with NOT and AND (NAND) gates. For example, here is an AND gate implemented using only NOT and OR gates:

AND using only NOR gatesNOT(OR(NOT(OR(A,A)),NOT(OR(B,B)))

With AND, OR and NOT, we can implement a half adder, like this:

Column AColumn B
A0
B1
Carry (AND)=AND(B1,B2)
Sum (XOR)=OR(AND(B1,NOT(B2)),AND(NOT(B1),B2))

By stringing together two half adders and OR-ing the carry bit, we can create a full adder:

BitSpreadsheet Formula
A0
B0
Cin0
Cout=AND(B2,B3)
Sum=OR(AND(B2,NOT(B3)),AND(NOT(B2),B3))
Cout=AND(B6,B4)
Sum=OR(AND(B4,NOT(B6)),AND(NOT(B4),B6))
Cout=OR(B7,B5)
Sum=B8

Implementing a 4-bit adder is just a matter of simply replicating the full adder logic four times:

8421
Input A0000
Input B0000
A=B2=C2=D2=E2
B=B3=C3=D3=E3
Cin=C12=D12=E120
Cout=AND(B5,B6)=AND(C5,C6)=AND(D5,D6)=AND(E5,E6)
Sum=OR(AND(B5,NOT(B6)),AND(NOT(B5),B6))=OR(AND(C5,NOT(C6)),AND(NOT(C5),C6))=OR(AND(D5,NOT(D6)),AND(NOT(D5),D6))=OR(AND(E5,NOT(E6)),AND(NOT(E5),E6))
Cout=AND(B7,B9)=AND(C7,C9)=AND(D7,D9)=AND(E7,E9)
Sum=OR(AND(B7,NOT(B9)),AND(NOT(B7),B9))=OR(AND(C7,NOT(C9)),AND(NOT(C7),C9))=OR(AND(D7,NOT(D9)),AND(NOT(D7),D9))=OR(AND(E7,NOT(E9)),AND(NOT(E7),E9))
Cout=OR(B8,B10)=OR(C8,C10)=OR(D8,D10)=OR(E8,E10)
Sum=B11=C11=D11=E11