Four bit adder: Difference between revisions

→‎{{header|APL}}: use built-in NAND operator ⍲ instead of defining a new one.
m (→‎{{header|Quackery}}: A bit more descriptive text.)
(→‎{{header|APL}}: use built-in NAND operator ⍲ instead of defining a new one.)
 
(3 intermediate revisions by 3 users not shown)
Line 517:
and ← { ⍺ ∧ ⍵ }
or ← { ⍺ ∨ ⍵ }
nand ← { ⍺ ⍲ ⍵ }
 
⍝ Build the complex gates
nand ← { not ⍺ and ⍵ } ⍝ similarly this can be built with composition as "nand ← not and"
xor ← { (⍺ and not ⍵) or (⍵ and not ⍺) }
 
Line 2,460:
1111 + 1111 = 1110 c=1
</pre>
=={{header|EasyLang}}==
<syntaxhighlight lang=easylang>
proc xor a b . r .
na = bitand bitnot a 1
nb = bitand bitnot b 1
r = bitor bitand a nb bitand b na
.
proc half_add a b . s c .
xor a b s
c = bitand a b
.
proc full_add a b c . s g .
half_add a c x y
half_add x b s z
g = bitor y z
.
proc bit4add a4 a3 a2 a1 b4 b3 b2 b1 . s4 s3 s2 s1 c .
full_add a1 b1 0 s1 c
full_add a2 b2 c s2 c
full_add a3 b3 c s3 c
full_add a4 b4 c s4 c
.
write "1101 + 1011 = "
bit4add 1 1 0 1 1 0 1 1 s4 s3 s2 s1 c
print c & s4 & s3 & s2 & s1
</syntaxhighlight>
{{out}}
<pre>
1101 + 1011 = 11000
</pre>
 
=={{header|Elixir}}==
{{works with|Elixir|1.1}}
Line 2,783 ⟶ 2,814:
 
[[File:Fōrmulæ - Four bit adder 06.png]]
 
<span>&nbsp;&nbsp;:</span>
 
[[File:Fōrmulæ - Four bit adder 07.png]]
Line 7,079 ⟶ 7,112:
=={{header|Wren}}==
{{trans|Go}}
<syntaxhighlight lang="ecmascriptwren">var xor = Fn.new { |a, b| a&(~b) | b&(~a) }
 
var ha = Fn.new { |a, b| [xor.call(a, b), a & b] }
1,480

edits