1
什麼是使用位語法向二進制數字添加任意大小的字符串的正確方法?一切都需要在小端。我已經試過這樣:Erlang:使用位語法添加小尾數格式的字符串
example() ->
Cmd = 16#4e584e43,
Text = "hello::",
<<Cmd:32/unsigned-little-integer,Text/little-bitstring>>.
但得到異常:
** exception error: bad argument
in function bit_size/1
called as bit_size("hello::")
in call from packet:example/0
in call from packet:main/0
是的,它的工作原理。我實際上也是通過使用它來實現它的:Header = << Cmd:32/unsigned-little-integer >>,list_to_binary([Header,Text])。謝謝! – dbryson 2011-12-16 15:48:30