[erlang-questions] How to create a bit array / bit vector

maverik a m4ver1k.a@REDACTED
Wed Feb 27 18:15:29 CET 2019


Hi Dieter,

Thank you that did work.
And thanks for sharing the doc, the constructing binaries part explains
this.

Regards
Maverick

On Wed, Feb 27, 2019 at 8:41 AM <dieter@REDACTED> wrote:

> Hi,
>
> how about
>
> new(Max) ->
>   <<1:1, 0:(Max-1)>>.
>
> This creates a binary with Max bits, with the MSB set to 1.
>
> I found this doc page very helpful:
> http://erlang.org/doc/programming_examples/bit_syntax.html
>
> Kind regards,
> Dieter
>
>
>
> Am Mi., Febr. 27, 2019 06:13 schrieb maverik a <m4ver1k.a@REDACTED>:
>
> Hi All,
>
> I'm trying to create a bit array in Erlang with simple new() , set() and
> get() operations.
>
> My new() looks like:
> new(Max) ->
> N = 1 bsl Max-1,
> <<N>>.
>
> but problem I'm stuck with is, my max can be at most 8 .
>
> How can I create a *bitstring *of Max length ?
>
> Regards
> Maverick
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20190227/ca2c5188/attachment.htm>


More information about the erlang-questions mailing list