-
-
Save dannywillems/b2bcebd1f972bd33d76bae387cfe2d8e to your computer and use it in GitHub Desktop.
Print bits le in OCaml
This file contains 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 print_bits_le b = | |
assert (b >= 0 && b <= 255) ; | |
let rec get_bits_le x acc i = | |
if i = 8 then acc | |
else | |
let acc = (x mod 2) :: acc in | |
get_bits_le (x lsr 1) acc (i + 1) | |
in | |
let bits_le = List.rev (get_bits_le b [] 0) in | |
List.iter print_int bits_le ; | |
print_endline "" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment