Binary digits: Difference between revisions

Add Refal
(→‎J: simply use an NVV fork)
(Add Refal)
 
(8 intermediate revisions by 5 users not shown)
Line 1,228:
UNTIL N% = 0
=A$</syntaxhighlight>
 
==={{header|Chipmunk Basic}}===
{{works with|Chipmunk Basic|3.6.4}}
<syntaxhighlight lang="qbasic">10 for c = 1 to 3
20 read n
30 print n;"-> ";vin$(n)
40 next c
80 end
100 sub vin$(n)
110 b$ = ""
120 n = abs(int(n))
130 '
140 b$ = str$(n mod 2)+b$
150 n = int(n/2)
160 if n > 0 then 130
170 vin$ = b$
180 end sub
200 data 5,50,9000</syntaxhighlight>
 
==={{header|Commodore BASIC}}===
Line 2,077 ⟶ 2,095:
9000: 10001100101000
</pre>
 
=={{header|Draco}}==
<syntaxhighlight lang="draco">proc main() void:
writeln(5:b);
writeln(50:b);
writeln(9000:b);
corp</syntaxhighlight>
{{out}}
<pre>101
110010
10001100101000</pre>
 
=={{header|dt}}==
Line 2,108 ⟶ 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,186 ⟶ 2,211:
 
=={{header|Elena}}==
ELENA 56.0x :
<syntaxhighlight lang="elena">import system'routines;
import extensions;
Line 2,192 ⟶ 2,217:
public program()
{
new int[]{5,50,9000}.forEach::(n)
{
console.printLine(n.toString(2))
Line 2,203 ⟶ 2,228:
10001100101000
</pre>
 
=={{header|Elixir}}==
Use <code>Integer.to_string</code> with a base of 2:
Line 3,525 ⟶ 3,551:
 
</pre >
=={{header|MACRO-11}}==
<syntaxhighlight lang="macro11"> .TITLE BINARY
.MCALL .TTYOUT,.EXIT
BINARY::MOV #3$,R5
BR 2$
1$: JSR PC,PRBIN
2$: MOV (R5)+,R0
BNE 1$
.EXIT
3$: .WORD ^D5, ^D50, ^D9000, 0
 
; PRINT R0 AS BINARY WITH NEWLINE
PRBIN: MOV #3$,R1
1$: MOV #'0,R2
ROR R0
ADC R2
MOVB R2,(R1)+
TST R0
BNE 1$
2$: MOVB -(R1),R0
.TTYOUT
BNE 2$
RTS PC
.BYTE 0,0,12,15
3$: .BLKB 16 ; BUFFER
.END BINARY</syntaxhighlight>
{{out}}
<pre>101
110010
10001100101000</pre>
 
=={{header|MAD}}==
MAD has basically no support for runtime generation of strings.
Line 3,555 ⟶ 3,612:
50: 110010
9000: 10001100101000</pre>
 
=={{header|Maple}}==
<syntaxhighlight lang="maple">
Line 5,046 ⟶ 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 {
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,125 ⟶ 5,204:
101010111111101001000101110110100000111011011011110111100110100100000100100001111101101110011101000101110110001101101000100100100110000111001010101011110010001111100011110100010101011011111111000110101110111100001011100111110000000010101100110101001010001001001011000000110000010010010100010010000001110100101000011111001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
</pre>
 
=={{header|Ring}}==
<syntaxhighlight lang="ring">
Line 5,140 ⟶ 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>.
Line 5,353 ⟶ 5,442:
10000
</pre>
 
=={{header|SETL}}==
<syntaxhighlight lang="setl">program binary_digits;
loop for n in [5, 50, 9000] do
print(bin n);
end loop;
 
op bin(n);
return reverse +/[str [n mod 2, n div:=2](1) : until n=0];
end op;
end program;</syntaxhighlight>
{{out}}
<pre>101
110010
10001100101000</pre>
 
=={{header|SequenceL}}==
Line 5,369 ⟶ 5,473:
["101","110010","10001100101000"]
</pre>
 
=={{header|Sidef}}==
<syntaxhighlight lang="ruby">[5, 50, 9000].each { |n|
Line 5,998 ⟶ 6,103:
=={{header|Wren}}==
{{libheader|Wren-fmt}}
<syntaxhighlight lang="ecmascriptwren">import "./fmt" for Fmt
System.print("Converting to binary:")
Line 6,010 ⟶ 6,115:
9000 -> 10001100101000
</pre>
 
=={{header|X86 Assembly}}==
Translation of XPL0. Assemble with tasm, tlink /t
2,094

edits