十六进制转 64 有符号十进制
我有十六进制数据,我必须转换为 64 有符号十进制数据..所以我认为有这样的步骤。 1.十六进制转二进制, 我没有编写自己的代码转换,而是使用此链接中给出的代码 http://necrobious.blogspot.com/2008/03/binary-to-hex-string-back-to-binary-in.html
bin_to_hexstr(Bin) ->
lists:flatten([io_lib:format("~2.16.0B", [X]) ||
X <- binary_to_list(Bin)]).
hexstr_to_bin(S) ->
hexstr_to_bin(S, []).
hexstr_to_bin([], Acc) ->
list_to_binary(lists:reverse(Acc));
hexstr_to_bin([X,Y|T], Acc) ->
{ok, [V], []} = io_lib:fread("~16u", [X,Y]),
hexstr_to_bin(T, [V | Acc]).
2.二进制转十进制, 如何实现这部分。?
或任何其他方式来实现十六进制 -> 的有符号十进制数据
64提前感谢
i have hexdecimal data i have to convert into 64 Signed Decimal data ..so i thought have follwoing step like this.
1.hexadecimal to binary,
instead of writing my own code conversion i m using code given in this link http://necrobious.blogspot.com/2008/03/binary-to-hex-string-back-to-binary-in.html
bin_to_hexstr(Bin) ->
lists:flatten([io_lib:format("~2.16.0B", [X]) ||
X <- binary_to_list(Bin)]).
hexstr_to_bin(S) ->
hexstr_to_bin(S, []).
hexstr_to_bin([], Acc) ->
list_to_binary(lists:reverse(Acc));
hexstr_to_bin([X,Y|T], Acc) ->
{ok, [V], []} = io_lib:fread("~16u", [X,Y]),
hexstr_to_bin(T, [V | Acc]).
2.binary to decimal,
how to achieve this part.?
or any other way to achieve the hexdecimal -> 64 Signed Decimal data
thanx in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要将整数转换为十六进制字符串,只需使用
erlang:integer_to_list(Int, 16)。
要转换回来,请使用erlang:list_to_integer(List, 16)。
这些函数我相信取 2 到 36 之间的基数。如果要将二进制文件与十六进制字符串相互转换,您可以使用列表推导式使其更加整洁:
要将整数转换为包含 64 位有符号整数的十六进制字符串,您现在可以执行以下操作:
To convert an integer to a hex string, just use
erlang:integer_to_list(Int, 16).
To convert back, useerlang:list_to_integer(List, 16).
These functions take a radix from 2 to 36 I believe.If you want to convert binaries to and from hex strings you can use list comprehensions to make it tidier:
To convert an integer to a hex string containing a 64 bit signed integer, you can now do:
这种方法怎么样?
What about this approach?