如何将浮点数转换为小端格式的字节 ?
喜欢
5.05 -> \x33\x33\x33\x33\x33\x33\x14\x40
答案 0 :(得分:4)
像这样:
# let v = Int64.bits_of_float 5.05 in
for i = 0 to 7 do
Printf.printf "%Lx " (Int64.logand 255L (Int64.shift_right v (i*8))) ;
done
;;
33 33 33 33 33 33 14 40 - : unit = ()