Skip to content

Binary digits

editable example

Click the pencil to open this in an editor, change it, and run it in your browser. The same solution is posted on Rosetta Code.

ghul
use IO.Std.write_line
binary(value: int) -> string =>
if value < 2 then "{value}" else "{binary(value / 2)}{value % 2}" fi
for value in [5, 50, 9000] do
write_line(binary(value))
od