Implementing Logic Gates in a Spreadsheet
Here are some of the basic logic gates, implemented as spreadsheet formulas.
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:
With AND, OR and NOT, we can implement a half adder, like this:
By string together two half adders and OR-ing the carry bit, we can create a full adder:
Implementing a 4-bit adder is just a matter of simply replicating the full adder logic four times:
| Gate | Spreadsheet Formula |
|---|---|
| AND | AND(A,B) |
| OR | OR(A,B) |
| NOT | NOT(B) |
| NAND | NOT(AND(A,B)) |
| NOR | NOT(OR(A,B)) |
| XOR | OR(AND(A;NOT(B));AND(NOT(A);B)) |
| XNOR | NOT(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 gates | NOT(OR(NOT(OR(A,A));NOT(OR(B,B))) |
With AND, OR and NOT, we can implement a half adder, like this:
| Column A | Column B |
|---|---|
| A | 0 |
| B | 1 |
| Carry (AND) | =AND(B1;B2) |
| Sum (XOR) | =OR(AND(B1;NOT(B2));AND(NOT(B1);B2)) |
By string together two half adders and OR-ing the carry bit, we can create a full adder:
| Bit | Spreadsheet Formula |
|---|---|
| A | 0 |
| B | 0 |
| Cin | 0 |
| 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:
| 8 | 4 | 2 | 1 | |
|---|---|---|---|---|
| Input A | 0 | 0 | 0 | 0 |
| Input B | 0 | 0 | 0 | 0 |
| A | =B2 | =C2 | =D2 | =E2 |
| B | =B3 | =C3 | =D3 | =E3 |
| Cin | =C12 | =D12 | =E12 | 0 |
| 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 |
Labels: boolean, gate, logic, spreadsheet

0 Comments:
Post a Comment
Links to this post:
Create a Link
<< Home