Four bit adder: Difference between revisions
→{{header|APL}}: mark carry explicitly in demo output
(→{{header|APL}}: Make GNU-compatible.) |
(→{{header|APL}}: mark carry explicitly in demo output) |
||
Line 513:
{{works with|Dyalog APL}}
{{works with|GNU APL}}
<lang apl>⍝ Our primitive "gates" are built-in, but
not ← { ~ ⍵ }
and ← { ⍺ ∧ ⍵ }
Line 522:
xor ← { (⍺ and not ⍵) or (⍵ and not ⍺) }
⍝ And the multigate components. Our bit vectors are MSB first, so for consistency
⍝ the carry bit is returned as the leftmost element as well.
half_adder ← { (⍺
⍝ GNU APL dfns can't have multiple statements, so the other adders are defined as tradfns
∇result ← c_in full_adder args ; c_in; a; b; s0; c0; s1; c1
(a b) ← args
(
(
result ← (c0 or c1), s1
∇
Line 545 ⟶ 546:
⍝ A demo function
demo ← {
⍝ A way to generate some random numbers for our demo
Line 556 ⟶ 557:
{{Out}}
<pre>
1
0 1 1
1 1
0 1 0 0
1
1 1 0 1 + 0 1
1 0
1 1 1 1 + 0 0 0 1 =
0
0 0 1 0 + 1
1
1 0 1 0 +
1 0 1 1
1 1 0
=={{header|AutoHotkey}}==
|