Skip to content

Instantly share code, notes, and snippets.

@gsg
Created Sep 18, 2016
Embed
What would you like to do?
let most_significant_bit =
max_int lxor (max_int lsr 1)
let print_int_binary n =
print_string "0b";
let rec loop started bit n =
if bit = 0 then ()
else
let b = n land bit in
if b = 0 then begin
if started then print_char '0';
loop started (bit lsr 1) n
end
else begin
print_char '1';
loop true (bit lsr 1) n
end in
loop false most_significant_bit n
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment