Skip to content

Commit eff9c44

Browse files
author
Derp McDerpson
authored
Create 2_bit_adder.lgc
1 parent 8f2fca3 commit eff9c44

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

tests/2_bit_adder.lgc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# XOR gate
2+
circ xor(a,b)->(!(a&b))&(a|b)
3+
# half-adder
4+
circ ha(a,b)->(a&b)+(xor(a,b))
5+
# full-adder
6+
circ fa(a,b,c)->(ha(a,b)[h])|(ha(ha(a,b)[t],c)[h])+(ha(ha(a,b)[t],c)[t])
7+
# 2-digit binary adder, accepts two two-bits
8+
circ two_digits(a,b)->(fa(a[h],b[h],(ha(a[t],b[t])[h]))[h])+(fa(a[h],b[h],(ha(a[t],b[t])[h]))[t])+(ha(a[t],b[t])[t])
9+
# Adds together 10 and 11, should return 101
10+
out two_digits(10,11)

0 commit comments

Comments
 (0)