如何在OCaml中以little-endian格式将float转换为字节?

时间:2013-04-25 15:36:31

标签: ocaml

如何将浮点数转换为小端格式的字节

喜欢

5.05 -> \x33\x33\x33\x33\x33\x33\x14\x40

1 个答案:

答案 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 = ()