Four bit adder: Difference between revisions

Adding Quackery. (Commentary to follow…)
(Adding Quackery. (Commentary to follow…))
Line 5,497:
if __name__ == '__main__':
test_fa4()</syntaxhighlight>
 
=={{header|Quackery}}==
 
<syntaxhighlight lang="Quackery"> [ over not
over and
unrot not
and or ] is xor ( a b --> a^b )
 
[ 2dup and
dip xor ] is halfadder ( a b --> s c )
 
[ halfadder
dip halfadder or ] is fulladder ( a b c --> s c )
 
[ 4 pack reverse unpack
4 times [ temp put ]
4 pack reverse
0 swap witheach
[ temp take fulladder ]
5 pack reverse unpack ] is 4bitadder ( b3 b2 b1 b0 a3 a2 a1 a0 --> c s3 s2 s1 s0 )
 
say "1100 + 1100 = "
1 1 0 0 1 1 0 0 4bitadder
5 pack witheach echo
cr
say "1100 + 1101 = "
1 1 0 0 1 1 0 1 4bitadder
5 pack witheach echo
cr
say "1100 + 1110 = "
1 1 0 0 1 1 1 0 4bitadder
5 pack witheach echo
cr
say "1100 + 1111 = "
1 1 0 0 1 1 1 1 4bitadder
5 pack witheach echo
cr
say "1101 + 0000 = "
1 1 0 1 0 0 0 0 4bitadder
5 pack witheach echo
cr
say "1101 + 0001 = "
1 1 0 1 0 0 0 1 4bitadder
5 pack witheach echo
cr
say "1101 + 0010 = "
1 1 0 1 0 0 1 0 4bitadder
5 pack witheach echo
cr
say "1101 + 0011 = "
1 1 0 1 0 0 1 1 4bitadder
5 pack witheach echo
cr</syntaxhighlight>
 
{{out}}
 
<pre>1100 + 1100 = 11000
1100 + 1101 = 11001
1100 + 1110 = 11010
1100 + 1111 = 11011
1101 + 0000 = 01101
1101 + 0001 = 01110
1101 + 0010 = 01111
1101 + 0011 = 10000</pre>
 
=={{header|Racket}}==
1,462

edits