What's the easiest way to convert an Int32.t
to binary? For example:
-1 -> "\255\255\255\255" ?
Edit: To use extlib, install it with yum and in the toplevel:
#use "topfind";;
#require "extlib";;
I would suggest using Bitstring for this kind of thing. You can find it here.
For example, in the toplevel:
# #use "topfind";;
# #camlp4o;;
# #require "unix";;
# #require "bitstring.syntax" ;;
# let data = Int32.of_int (-1);;
# let bits = BITSTRING { data: 32 } ;;
then you can perform various conversions on the bitstring including writing it to a binary file or to stdout or to a string:
# Bitstring.string_of_bitstring bits ;;
- : string = "\255\255\255\255"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With