Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Concatenating BitStrings (Not Binaries) in Erlang

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

like image 398
GTDev Avatar asked Jun 09 '12 18:06

GTDev


Video Answer


1 Answers

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>>
like image 65
marcelog Avatar answered Sep 28 '22 07:09

marcelog