Anonymous user
Four bit adder: Difference between revisions
m
→{{header|REXX}}: simplified program, added/changed whitespace and comments, used a template for the output section.
m (→{{header|REXX}}: simplified program, added/changed whitespace and comments, used a template for the output section.) |
|||
Line 5,052:
::::* the '''&''' symbol is a logical '''AND'''.
<lang rexx>/*REXX program displays (all) the sums of a full 4─bit adder (with carry). */
call hdr1;
/* [↓] traipse thru all possibilities.*/
do j=0 for 16
do m=0 for 4; a.m= bit(j, m)
end /*m*/
do k=0 for 16
do m=0 for 4; b.m= bit(k, m)
end /*m*/
sc= 4bitAdder(a., b.)
say translate( space(z, 0), , '~') /*translate tildes (~) to blanks in Z. */
end /*k*/
end /*j*/
call hdr2;
exit
/*──────────────────────────────────────────────────────────────────────────────────────*/
bit: procedure; parse arg x,y; return substr( reverse( x2b( d2x(x) ) ), y+1, 1)
halfAdder: procedure expose c; parse arg x,y; c= x & y; return x && y
hdr1: say 'aaaa + bbbb = c, sum [c=carry]'; return
hdr2: say '════ ════ ══════' ; return
/*──────────────────────────────────────────────────────────────────────────────────────*/
fullAdder: procedure expose c; parse arg x,y,fc
/*──────────────────────────────────────────────────────────────────────────────────────*/
4bitAdder: procedure expose s. a. b.; carry.= 0
end /*j*/;
▲'''output''' (most lines have been elided):
<pre style="height:63ex">
aaaa + bbbb = c, sum [c=carry]
|