Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ember.js/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
OCaml int到二进制字符串的转换_Ocaml_Type Conversion - Fatal编程技术网

OCaml int到二进制字符串的转换

OCaml int到二进制字符串的转换,ocaml,type-conversion,Ocaml,Type Conversion,将Int32.t转换为二进制的最简单方法是什么?例如: -1->“\255\255\255\255” 编辑: 要使用extlib,请使用yum并在顶层安装它: #use "topfind";; #require "extlib";; # #use "topfind";; # #camlp4o;; # #require "unix";; # #require "bitstring.syntax" ;; # let data = Int32.of_int (

Int32.t
转换为二进制的最简单方法是什么?例如: -1->“\255\255\255\255”

编辑: 要使用extlib,请使用yum并在顶层安装它:

#use "topfind";;
#require "extlib";;
# #use "topfind";;
# #camlp4o;;
# #require "unix";;
# #require "bitstring.syntax" ;;
# let data = Int32.of_int (-1);;
# let bits = BITSTRING { data: 32 } ;;
我建议用它来做这类事情。你可以找到它

例如,在顶层:

#use "topfind";;
#require "extlib";;
# #use "topfind";;
# #camlp4o;;
# #require "unix";;
# #require "bitstring.syntax" ;;
# let data = Int32.of_int (-1);;
# let bits = BITSTRING { data: 32 } ;;
然后可以对位字符串执行各种转换,包括将其写入二进制文件、标准输出或字符串:

# Bitstring.string_of_bitstring bits ;;
- : string = "\255\255\255\255"
使用:

#让io=io.output_string();;
val io:字符串io.output=
#IO.write_i32 IO(-1);;
-:单位=()
#收尾;;
-:string=“\255\255\255\255”