Created
September 18, 2016 07:55
-
-
Save gsg/87795be559b34513fc4fa0ff7a8530e0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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