Four bit adder: Difference between revisions

m
(→‎{{header|APL}}: mark carry explicitly in demo output)
Line 514:
{{works with|GNU APL}}
<lang apl>⍝ Our primitive "gates" are built-in, but let's give them names
not ← { ~ ⍵ } ⍝ in Dyalog these assignments can be simplified to "not ← ~", "and ← ∧", etc.
not ← { ~ ⍵ }
and ← { ⍺ ∧ ⍵ }
or ← { ⍺ ∨ ⍵ }
 
⍝ Build the complex gates
nand ← { not ⍺ and ⍵ } ⍝ similarly this can be built with composition as "nand ← not and"
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 leftmostleft elementresult as well.
half_adder ← { (⍺ and ⍵), ⍺ xor ⍵ } ⍝ returns carry, sum
 
1,480

edits