Concatenating BitStrings (Not Binaries) in Erlang

笑着哭i 提交于 2019-12-22 06:36:23

问题


How do you concatenate bitstrings. I mean bitstrings because I do not know the number of bytes to be a multiple of 8.

A = <<3:2>>
B = <<1:1>>
C = <<15:4>>

Solution should A|B|C should be <<127:7>>

Thanks


回答1:


Construct the binary using /bitstring and all the previous values. Here's an example, running in the erlang shell:

1> A = <<3:2>>.
<<3:2>>
2> B = <<1:1>>.
<<1:1>>
3> C = <<15:4>>.
<<15:4>>
4> D = <<A/bitstring, B/bitstring, C/bitstring>>.
<<127:7>>


来源:https://stackoverflow.com/questions/10963359/concatenating-bitstrings-not-binaries-in-erlang

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!