Binary digits: Difference between revisions

Add Refal
(add MACRO)
(Add Refal)
(4 intermediate revisions by 3 users not shown)
Line 2,095:
9000: 10001100101000
</pre>
 
=={{header|Draco}}==
<syntaxhighlight lang="textdraco">proc main() void:
writeln(5:b);
writeln(50:b);
writeln(9000:b);
corp</syntaxhighlight>
{{out}}
<pre>101
110010
10001100101000</pre>
 
=={{header|dt}}==
Line 2,126 ⟶ 2,137:
 
=={{header|EasyLang}}==
<syntaxhighlight lang="easylang">
 
<syntaxhighlight lang="text">
func$ bin num .
b$ = ""
ifwhile num => 01
b$ = "0"
.
while num > 0
b$ = num mod 2 & b$
num = num div 2
.
return num & b$
.
print bin 25
print bin 50
print bin 9000
Line 2,204 ⟶ 2,211:
 
=={{header|Elena}}==
ELENA 56.0x :
<syntaxhighlight lang="elena">import system'routines;
import extensions;
Line 2,210 ⟶ 2,217:
public program()
{
new int[]{5,50,9000}.forEach::(n)
{
console.printLine(n.toString(2))
Line 2,221 ⟶ 2,228:
10001100101000
</pre>
 
=={{header|Elixir}}==
Use <code>Integer.to_string</code> with a base of 2:
Line 5,096 ⟶ 5,104:
=={{header|Retro}}==
<syntaxhighlight lang="retro">9000 50 5 3 [ binary putn cr decimal ] times</syntaxhighlight>
=={{header|Refal}}==
<syntaxhighlight lang="refal">$ENTRY Go {
= <Prout <Binary 5>
<Binary 50>
<Binary 9000>>;
};
 
Binary {
0 = '0\n';
s.N = <Binary1 s.N> '\n';
};
 
Binary1 {
b$0 = "0";
s.N, <Divmod s.N 2>: (s.R) s.D = <Binary1 s.R> <Symb s.D>;
};</syntaxhighlight>
{{out}
<pre>101
110010
10001100101000</pre>
 
=={{header|REXX}}==
This version handles the special case of zero simply.
Line 5,175 ⟶ 5,204:
101010111111101001000101110110100000111011011011110111100110100100000100100001111101101110011101000101110110001101101000100100100110000111001010101011110010001111100011110100010101011011111111000110101110111100001011100111110000000010101100110101001010001001001011000000110000010010010100010010000001110100101000011111001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
</pre>
 
=={{header|Ring}}==
<syntaxhighlight lang="ring">
Line 5,190 ⟶ 5,220:
next
</syntaxhighlight>
 
=={{header|Roc}}==
<syntaxhighlight lang="roc">binstr : Int * -> Str
binstr = \n ->
if n < 2 then
Num.toStr n
else
Str.concat (binstr (Num.shiftRightZfBy n 1)) (Num.toStr (Num.bitwiseAnd n 1))</syntaxhighlight>
 
=={{header|RPL}}==
RPL handles both floating point numbers and binary integers, but the latter are visualized with a <code>#</code> at the beginning and a specific letter at the end identifying the number base, according to the current display mode setting. 42 will then be displayed # 42d, # 2Ah, # 52o or # 101010b depending on the display mode set by resp. <code>DEC</code>, <code>HEX</code>, <code>OCT</code> or <code>BIN</code>.
2,096

edits