整数到二进制Erlang [英] Integer to Binary Erlang
本文介绍了整数到二进制Erlang的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
543 =<543>> ;
如果没有
integer_to_list(list_to_binary(K))。
解决方案
如果要将543转换为< 543>>我不认为你可以找到比以下更快的东西:
1> list_to_binary(integer_to_list(543))。
<543>>
因为在这种情况下,这两个函数都是在C中实现的。
如果要将整数转换为最小二进制表示形式,可以使用二进制:encode_unsigned 功能,新的二进制模块如下:
1>二进制:encode_unsigned(543)。
< 2,31>>
2> binary:encode_unsigned(543,little)。
< 31,2>>
I am trying to make an integer into a binary:
543 = <<"543">>
How can I do this without
integer_to_list(list_to_binary(K)).
解决方案
If you want to convert 543 to <<"543">> I don't think you can find something faster than:
1> list_to_binary(integer_to_list(543)).
<<"543">>
Because in this case both functions implemented in C.
If you want to convert integer to the smallest possible binary representation you can use binary:encode_unsigned function from the new binary module like this:
1> binary:encode_unsigned(543).
<<2,31>>
2> binary:encode_unsigned(543, little).
<<31,2>>
这篇关于整数到二进制Erlang的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文