Binary digits: Difference between revisions

Add MAD
(Add Cowgol)
(Add MAD)
Line 2,967:
 
</pre >
 
=={{header|MAD}}==
MAD has basically no support for runtime generation of strings.
Therefore, this program works by calculating an integer whose decimal representation
matches the binary representation of the input, e.g. <code>BINARY.(5)</code> is <code>101</code>.
 
<lang MAD> NORMAL MODE IS INTEGER
INTERNAL FUNCTION(NUM)
ENTRY TO BINARY.
BTEMP = NUM
BRSLT = 0
BDIGIT = 1
BIT WHENEVER BTEMP.NE.0
BRSLT = BRSLT + BDIGIT * (BTEMP-BTEMP/2*2)
BTEMP = BTEMP/2
BDIGIT = BDIGIT * 10
TRANSFER TO BIT
END OF CONDITIONAL
FUNCTION RETURN BRSLT
END OF FUNCTION
THROUGH SHOW, FOR VALUES OF N = 5, 50, 9000
SHOW PRINT FORMAT FMT, N, BINARY.(N)
 
VECTOR VALUES FMT = $I4,2H: ,I16*$
END OF PROGRAM </lang>
{{out}}
<pre> 5: 101
50: 110010
9000: 10001100101000</pre>
 
=={{header|Maple}}==
2,119

edits