Binary digits: Difference between revisions

Add Refal
(Add Refal)
 
(41 intermediate revisions by 17 users not shown)
Line 1,087:
EndFunc ;==>IntToBin
</syntaxhighlight>
 
=={{header|AWK}}==
<syntaxhighlight lang="awk">BEGIN {
print tobinary(0)
print tobinary(1)
print tobinary(5)
print tobinary(50)
Line 1,095 ⟶ 1,098:
 
function tobinary(num) {
outstr = ""num % 2
lwhile (num = int(num / 2))
while outstr = (num l% 2) {outstr
if ( l%2 == 0 ) {
outstr = "0" outstr
} else {
outstr = "1" outstr
}
l = int(l/2)
}
# Make sure we output a zero for a value of zero
if ( outstr == "" ) {
outstr = "0"
}
return outstr
}</syntaxhighlight>
 
=={{header|Axe}}==
This example builds a string backwards to ensure the digits are displayed in the correct order. It uses bitwise logic to extract one bit at a time.
Line 1,235 ⟶ 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 1,397 ⟶ 1,408:
PRINT " -> "; BIN$(9000)
END</syntaxhighlight>
 
==={{header|XBasic}}===
{{works with|Windows XBasic}}
<syntaxhighlight lang="qbasic">PROGRAM "binardig"
VERSION "0.0000"
 
DECLARE FUNCTION Entry ()
 
FUNCTION Entry ()
DIM a[3]
a[0] = 5
a[1] = 50
a[2] = 9000
FOR i = 0 TO 2
PRINT FORMAT$ ("####", a[i]); " -> "; BIN$(a[i])
NEXT i
 
END FUNCTION
END PROGRAM</syntaxhighlight>
 
=={{header|Batch File}}==
This num2bin.bat file handles non-negative input as per the requirements with no leading zeros in the output. Batch only supports signed integers. This script also handles negative values by printing the appropriate two's complement notation.
Line 2,063 ⟶ 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}}==
<syntaxhighlight lang="dt">[dup 1 gt? [dup 2 % swap 2 / loop] swap do?] \loop def
 
[\loop doin rev \to-string map "" join] \bin def
 
[0 1 2 5 50 9000] \bin map " " join pl</syntaxhighlight>
{{out}}
<pre>0 1 10 101 110010 10001100101000</pre>
 
=={{header|Dyalect}}==
 
A default <code>ToString</code> method of type <code>Integer</code> is overridenoverridden and returns a binary representation of a number:
 
<syntaxhighlight lang="dyalect">func Integer.ToString() {
Line 2,080 ⟶ 2,133:
print("5 == \(5), 50 = \(50), 1000 = \(9000)")</syntaxhighlight>
 
{{out}}
<pre>5 == 101, 50 = 110010, 1000 = 10001100101000</pre>
 
<pre>5 == 101, 50 = 110010, 1000 = 10001100101000</pre>
=={{header|EasyLang}}==
<syntaxhighlight lang="easylang">
 
func$ bin num .
<syntaxhighlight lang="text">
func to2 n . rb$ .= ""
if nwhile num > 01
call to2 nb$ div= num mod 2 r& b$
r$ & num = nnum moddiv 2
else .
return r$num =& ""b$
.
.
print bin 5
func pr2 n . .
print bin 50
call to2 n r$
print bin 9000
if r$ = ""
r$ = "0"
.
print r$
.
call pr2 5
call pr2 50
call pr2 9000
</syntaxhighlight>
{{out}}
 
<pre>
101
Line 2,128 ⟶ 2,172:
=={{header|Ecstasy}}==
<syntaxhighlight lang="java">
module BinaryDigits {
{
@Inject Console console;
void run() {
Int64[] tests = [0, 1, 5, 50, 9000];
{
Int[] tests = [0, 1, 5, 50, 9000];
 
Int longestInt = tests.map(n -> n.estimateStringLength()).reduce(0, (max, len) -> max.maxOf(len));
Int longestBin = tests.map(n -> (64-n.leadingZeroCount).maxOf(1)) .reduce(0, (max, len) -> max.maxOfnotLessThan(len));
Int longestBin = tests.map(n -> (64-n.leadingZeroCount).notLessThan(1))
.reduce(0, (max, len) -> max.maxOf(len));
 
function String(IntInt64) num = n -> {
{
Int indent = longestInt - n.estimateStringLength();
return $"{' ' * indent}{n}";
};
 
function String(IntInt64) bin = n -> {
{
Int index = n.leadingZeroCount.minOf(63);
Int indent = index - (64 - longestBin);
val bits = n.toBitArray()[index ..< 64];
return $"{' ' * indent}{bits.toString().substring(2)}";
};
 
for (IntInt64 test : tests) {
console.print($"The decimal value {num(test)} should produce an output of {bin(test)}");
{
console.println($"The decimal value {num(test)} should produce an output of {bin(test)}");
}
}
}
}
</syntaxhighlight>
 
{{out}}
Output:
<pre>
<syntaxhighlight>
The decimal value 0 should produce an output of 0
The decimal value 1 should produce an output of 1
Line 2,167 ⟶ 2,208:
The decimal value 50 should produce an output of 110010
The decimal value 9000 should produce an output of 10001100101000
</pre>
</syntaxhighlight>
 
=={{header|Elena}}==
ELENA 56.0x :
<syntaxhighlight lang="elena">import system'routines;
import extensions;
Line 2,176 ⟶ 2,217:
public program()
{
new int[]{5,50,9000}.forEach::(n)
{
console.printLine(n.toString(2))
Line 2,187 ⟶ 2,228:
10001100101000
</pre>
 
=={{header|Elixir}}==
Use <code>Integer.to_string</code> with a base of 2:
<syntaxhighlight lang="elixir">
IO.puts Integer.to_string(5, 2)
</syntaxhighlight>
Or, using the pipe operator:
Line 2,197 ⟶ 2,239:
</syntaxhighlight>
<syntaxhighlight lang="elixir">
[5,50,9000] |> Enum.each(fn n -> IO.puts Integer.to_string(n, 2) end)
</syntaxhighlight>
 
Line 2,206 ⟶ 2,248:
10001100101000
</pre>
With Enum.map/2
<syntaxhighlight lang="elixir">
Enum.map([5, 50, 9000], fn n -> IO.puts Integer.to_string(n, 2) end)
</syntaxhighlight>
 
{{out}}
<pre>
101
110010
10001100101000
</pre>
With list comprehension
<syntaxhighlight lang="elixir">
for n <- [5, 50, 9000] do IO.puts Integer.to_string(n, 2) end
</syntaxhighlight>
 
{{out}}
<pre>
101
110010
10001100101000
</pre>
 
=={{header|Emacs Lisp}}==
<syntaxhighlight lang="lisp">
(defun int-to-binary (val)
(let ((x val) (result ""))
(while (> x 0)
(setq result (concat (number-to-string (% x 2)) result))
(setq x (/ x 2)))
result))
 
(message "5 => %s" (int-to-binary 5))
(message "50 => %s" (int-to-binary 50))
(message "9000 => %s" (int-to-binary 9000))
</syntaxhighlight>
{{out}}
<pre>
5 => 101
50 => 110010
9000 => 10001100101000
</pre>
 
=={{header|Epoxy}}==
<syntaxhighlight lang="epoxy">fn bin(a,b:true)
Line 2,627 ⟶ 2,712:
import Numeric
import Text.Printf
 
-- Use the built-in function showBin.
toBin n = showBin n ""
 
-- Use the built-in function showIntAtBase.
Line 2,686 ⟶ 2,774:
50 -> 110010
9000 -> 10001100101000</pre>
 
=={{header|Icon}} and {{header|Unicon}}==
There is no built-in way to output the bit string representation of an whole number in Icon and Unicon. There are generalized radix conversion routines in the Icon Programming Library that comes with every distribution. This procedure is a customized conversion routine that will populate and use a tunable cache as it goes.
Line 2,745 ⟶ 2,834:
</pre>
=={{header|J}}==
Generate a list of binary digits and use it to select characters from string '01'.
<syntaxhighlight lang="j"> tobin=: -.&' '@":@#:
<syntaxhighlight lang="j"> tobin=: '01'{~#:
tobin 5
101
Line 2,752 ⟶ 2,842:
tobin 9000
10001100101000</syntaxhighlight>
Uses implicit output.
Algorithm: Remove spaces from the character list which results from formatting the binary list which represents the numeric argument.
 
I am using implicit output.
=={{header|Java}}==
<p>
<syntaxhighlight lang="java">public class Main {
The <code>Integer</code> class offers the <code>toBinaryString</code> method.
public static void main(String[] args) {
</p>
System.out.println(Integer.toBinaryString(5));
<syntaxhighlight lang="java">
System.out.println(Integer.toBinaryString(50));
System.out.println(Integer.toBinaryString(9000)5);
</syntaxhighlight>
}
}</syntaxhighlight lang="java">
Integer.toBinaryString(50);
{{out}}
</syntaxhighlight>
<pre>101
<syntaxhighlight lang="java">
Integer.toBinaryString(9000);
</syntaxhighlight>
<p>
If you printed these values you would get the following.
</p>
<pre>
101
110010
10001100101000</pre>
</pre>
 
=={{header|JavaScript}}==
===ES5===
Line 2,874 ⟶ 2,973:
9000 -> 一〇〇〇一一〇〇一〇一〇〇〇</pre>
=={{header|Joy}}==
<syntaxhighlight lang="joy">HIDEDEFINE bin == "" [pop 1 >] [[2 div "01" of] dip cons] while ["01" of] dip cons.
 
_ == [null] [pop] [2 div swap] [48 + putch] linrec
[0 1 2 5 50 9000] [bin] map put.</syntaxhighlight>
IN
{{out}}
int2bin == [null] [48 + putch] [_] ifte '\n putch
<pre>["0" "1" "10" "101" "110010" "10001100101000"]</pre>
END</syntaxhighlight>
 
Using int2bin:
<syntaxhighlight lang="joy">0 setautoput
0 int2bin
5 int2bin
50 int2bin
9000 int2bin.</syntaxhighlight>
=={{header|jq}}==
<syntaxhighlight lang="jq">def binary_digits:
Line 2,929 ⟶ 3,023:
"10001100101000")</syntaxhighlight>
=={{header|Kotlin}}==
<syntaxhighlight lang="scalakotlin">// version 1.0.5-2
fun main() {
 
fun main(args: Array<String>) {
val numbers = intArrayOf(5, 50, 9000)
numbers.forEach { println("$it -> ${it.toString(2)}") }
for (number in numbers) println("%4d".format(number) + " -> " + Integer.toBinaryString(number))
}</syntaxhighlight>
 
{{out}}
<pre>
5 -> 101
50 -> 110010
9000 -> 10001100101000
</pre>
 
=={{header|Ksh}}==
<syntaxhighlight lang="ksh">function bin {
typeset -i2 n=$1
print -r -- "${n#2#}"
}
 
print -r -- $(for i in 0 1 2 5 50 9000; do bin "$i"; done)</syntaxhighlight>
{{out}}
<pre>0 1 10 101 110010 10001100101000</pre>
 
=={{header|Lambdatalk}}==
<syntaxhighlight lang="scheme">
Line 2,965 ⟶ 3,069:
50 -> 110010
9000 -> 10001100101000
</syntaxhighlight>
 
As a (faster) alternative we can ask some help from Javascript who knows how to do:
 
<syntaxhighlight lang="scheme">
1) we add to the lambdatalk's dictionary the Javascript primitive "dec2bin"
{script
LAMBDATALK.DICT["dec2bin"] = function() {
return Number( arguments[0].trim() ).toString(2)
};
}
 
2) we use it in the wiki page:
'{S.map dec2bin 5 50 9000}
-> 101 110010 10001100101000
}
</syntaxhighlight>
 
=={{header|Lang}}==
<syntaxhighlight lang="lang">
fn.println(fn.toTextBase(5, 2))
fn.println(fn.toTextBase(50, 2))
fn.println(fn.toTextBase(9000, 2))
</syntaxhighlight>
 
=={{header|Lang5}}==
<syntaxhighlight lang="lang5">'%b '__number_format set
Line 3,319 ⟶ 3,446:
110010
10001100101000</pre>
 
=={{header|Lua}}==
===Lua - Iterative===
<syntaxhighlight lang="lua">function dec2bin (n)
local bin = ""
while n > 01 do
bin = n % 2 .. bin
n = math.floor(n / 2)
end
return n .. bin
end
 
Line 3,337 ⟶ 3,465:
110010
10001100101000</pre>
 
===Lua - Recursive===
{{works with|Lua|5.3+}}
<syntaxhighlight lang="lua">function-- dec2binfor Lua 5.1/5.2 use math.floor(n/2) instead of n>>1, bin)and n%2 instead of n&1
 
bin = (n&1) .. (bin or "") -- use n%2 instead of n&1 for Lua 5.1/5.2
function dec2bin(n)
return n>1 and dec2bin(n//2, bin) or bin -- use math.floor(n/2) instead of n//2 for Lua 5.1/5.2
return n>1 and dec2bin(n>>1)..(n&1) or n
end
 
Line 3,351 ⟶ 3,481:
110010
10001100101000</pre>
 
=={{header|M2000 Interpreter}}==
<syntaxhighlight lang="m2000 interpreter">
Line 3,420 ⟶ 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,450 ⟶ 3,612:
50: 110010
9000: 10001100101000</pre>
 
=={{header|Maple}}==
<syntaxhighlight lang="maple">
Line 3,541 ⟶ 3,704:
io.write_string(int_to_base_string(N, 2), !IO),
io.nl(!IO).</syntaxhighlight>
 
=={{header|min}}==
{{works with|min|0.1937.30}}
<syntaxhighlight lang="min">(2 over over mod 'div dip) :divmod2
symbol bin
(int :i ==> str :s)
(i (dup 2 <) 'string ('odd? ("1") ("0") if swap 1 shr) 'prefix linrec @s)
) ::
 
(0 1 2 5 50 9000) 'bin map ", " join puts!</syntaxhighlight>
(
{{out}}
:n () =list
<pre>0, 1, 10, 101, 110010, 10001100101000</pre>
(n 0 >) (n divmod2 list append #list @n) while
list reverse 'string map "" join
"^0+" "" replace ;remove leading zeroes
) :bin
 
(5 50 9000) (bin puts) foreach</syntaxhighlight>
{{out}}
<pre>
101
110010
10001100101000
</pre>
=={{header|MiniScript}}==
=== Iterative ===
Line 3,832 ⟶ 3,990:
=={{header|OCaml}}==
<syntaxhighlight lang="ocaml">let bin_of_int d =
let last_digit n = [|"0"; "1"|].(n land 1) in
if d < 0 then invalid_arg "bin_of_int" else
let rec aux lst = function
if d = 0 then "0" else
let rec aux| acc0 d-> =lst
if| dn =-> 0aux then(last_digit accn else:: lst) (n lsr 1)
aux (string_of_int (d land 1) :: acc) (d lsr 1)
in
String.concat "" (aux [last_digit d] (d lsr 1))
 
(* test *)
let () =
let d() = read_int[0; ()1; 2; 5; 50; 9000; in-5]
Printf|> List.printfmap bin_of_int |> String.concat "%8s\n, " (bin_of_int|> d)print_endline</syntaxhighlight>
The output of negative integers is interesting, as it shows the [[wp:Two's_complement|two's complement]] representation and the width of Int on the system.
{{out}}
<pre>
0, 1, 10, 101, 110010, 10001100101000, 1111111111111111111111111111011
</pre>
 
=={{header|Oforth}}==
 
Line 4,941 ⟶ 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,020 ⟶ 5,204:
101010111111101001000101110110100000111011011011110111100110100100000100100001111101101110011101000101110110001101101000100100100110000111001010101011110010001111100011110100010101011011111111000110101110111100001011100111110000000010101100110101001010001001001011000000110000010010010100010010000001110100101000011111001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
</pre>
 
=={{header|Ring}}==
<syntaxhighlight lang="ring">
Line 5,035 ⟶ 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>.
 
To comply with the task, we have just to remove these characters.
{{works with|Halcyon Calc|4.2.7}}
≪ BIN R→B →STR 3 OVER SIZE 1 - SUB ≫
'→PLNB' STO
{{in}}
<pre>
5 →PLNB
50 →PLNB
9000 →PLNB
</pre>
{{out}}
<pre>
3: "101"
2: "110010"
1: "10001100101000"
</pre>
 
=={{header|Ruby}}==
<syntaxhighlight lang="ruby">[5,50,9000].each do |n|
Line 5,047 ⟶ 5,261:
110010
10001100101000</pre>
 
=={{header|Run BASIC}}==
<syntaxhighlight lang="runbasic">input "Number to convert:";a
Line 5,106 ⟶ 5,321:
110010
10001100101000</pre>
 
=={{header|S-BASIC}}==
<syntaxhighlight lang = "BASIC">
 
rem - Return binary representation of n
 
function bin$(n = integer) = string
var s = string
s = ""
while n > 0 do
begin
if (n - (n / 2) * 2) = 0 then
s = "0" + s
else
s = "1" + s
n = n / 2
end
end = s
 
rem - exercise the function
 
print "5 = "; bin$(5)
print "50 = "; bin$(50)
print "9000 = "; bin$(9000)
 
end
</syntaxhighlight>
{{out}}
<pre>
5 = 101
50 = 110010
9000 = 10001100101000
</pre>
 
=={{header|Scala}}==
Scala has an implicit conversion from <code>Int</code> to <code>RichInt</code> which has a method <code>toBinaryString</code>.
Line 5,120 ⟶ 5,369:
(display (number->string 50 2)) (newline)
(display (number->string 9000 2)) (newline)</syntaxhighlight>
 
=={{header|sed}}==
<syntaxhighlight lang="sed">: a
s/^0*/d/
/^d[1-9]/t b
b e
: b
s/d[01]/0&/
s/d[23]/1&/
s/d[45]/2&/
s/d[67]/3&/
s/d[89]/4&/
t d
b a
: c
s/D[01]/5&/
s/D[23]/6&/
s/D[45]/7&/
s/D[67]/8&/
s/D[89]/9&/
t d
b a
: d
s/[dD][02468]/d/
t b
s/[dD][13579]/D/
t c
: e
s/^dD/D/
y/dD/01/</syntaxhighlight>
{{out}}
<pre>
$ echo $(seq 0 16 | sed -f binary-digits.sed)
0 1 10 11 100 101 110 111 1000 1001 1010 1011 1100 1101 1110 1111 10000
$ printf '%s\n' 50 9000 1996677482718355282095361651 | sed -f binary-digits.sed
110010
10001100101000
1100111001110011100111001110011100111001110011100111001110011100111001110011100111001110011
</pre>
 
=={{header|Seed7}}==
This example uses the [http://seed7.sourceforge.net/libraries/integer.htm#%28in_integer%29radix%28in_integer%29 radix] operator to write a number in binary.
Line 5,153 ⟶ 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}}==
<syntaxhighlight lang="sequencel">main := toBinaryString([5, 50, 9000]);
Line 5,168 ⟶ 5,473:
["101","110010","10001100101000"]
</pre>
 
=={{header|Sidef}}==
<syntaxhighlight lang="ruby">[5, 50, 9000].each { |n|
Line 5,395 ⟶ 5,701:
 
0 OK, 0:775</pre>
 
=={{header|UNIX Shell}}==
Since POSIX does not specify local variables, make use of <code>set</code> for highest portability.
<syntaxhighlight lang="sh"># Define a function to output binary digits
<syntaxhighlight lang="sh">bin() {
tobinary() {
set -- "${1:-0}" ""
# We use the bench calculator for our conversion
echo while [ 1 -lt "obase=2;$1"|bc ]
do
set -- $(($1 >> 1)) $(($1 & 1))$2
done
echo "$1$2"
}
 
echo $(for i in 0 1 2 5 50 9000; do bin $i; done)</syntaxhighlight>
# Call the function with each of our values
{{out}}
tobinary 5
<pre>0 1 10 101 110010 10001100101000</pre>
tobinary 50</syntaxhighlight>
 
=={{header|VBA}}==
'''2 ways :'''
Line 5,661 ⟶ 5,973:
110010
10001100101000</pre>
=={{header|VBScript}}==
Using no Math....
<syntaxhighlight lang="vb">
Option Explicit
Dim bin
bin=Array(" "," I"," I "," II"," I "," I I"," II "," III","I ","I I","I I ","I II"," I ","II I","III ","IIII")
 
Function num2bin(n)
Dim s,i,n1,n2
s=Hex(n)
For i=1 To Len(s)
n1=Asc(Mid(s,i,1))
If n1>64 Then n2=n1-55 Else n2=n1-48
num2bin=num2bin & bin(n2)
Next
num2bin=Replace(Replace(LTrim(num2bin)," ","0"),"I",1)
End Function
Sub print(s):
On Error Resume Next
WScript.stdout.WriteLine (s)
If err= &h80070006& Then WScript.Echo " Please run this script with CScript": WScript.quit
End Sub
print num2bin(5)
print num2bin(50)
print num2bin(9000)
</syntaxhighlight>
{{out}}
<small>
<pre>
101
110010
10001100101000
</pre>
</small>
 
=={{header|Whitespace}}==
 
Line 5,741 ⟶ 6,089:
pop
ret</syntaxhighlight>
 
=={{header|Wortel}}==
Using JavaScripts buildin toString method on the Number object, the following function takes a number and returns a string with the binary representation:
Line 5,754 ⟶ 6,103:
=={{header|Wren}}==
{{libheader|Wren-fmt}}
<syntaxhighlight lang="ecmascriptwren">import "./fmt" for Fmt
System.print("Converting to binary:")
Line 5,766 ⟶ 6,115:
9000 -> 10001100101000
</pre>
 
=={{header|X86 Assembly}}==
Translation of XPL0. Assemble with tasm, tlink /t
2,093

edits