Created
March 29, 2020 21:07
-
-
Save rizo/7b433d4a6d6a19ff20c9b51157b50405 to your computer and use it in GitHub Desktop.
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 int_to_bin_byte d = | |
if d < 0 then invalid_arg "bin_of_int" else | |
if d = 0 then "0" else | |
let rec aux acc d = | |
if d = 0 then acc else | |
aux (string_of_int (d land 1) :: acc) (d lsr 1) | |
in | |
let res = String.concat "" (aux [] d) in | |
if String.length res mod 8 <> 0 then | |
String.make (8 - String.length res mod 8) '0' ^ res | |
else res | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment