Re: creating a binary number

Roger Lipscombe <[email protected]>
Newsgroups gmane.comp.lang.erlang.general
Message-ID <CAJgnQd9cN6+4i9dXfrc_B0REYZDRsyY_PwEowLdPS6oXOGju+A@mail.gmail.com>
It's kinda hard to figure out what you're trying to do, but if you
find that you're actually dealing with numbers, rather than sequences
of 0 and 1, the simplest way to do this is:

io_lib:format("~.2B", [643627467]).
"100110010111001111100111001011"

On Thu, 9 Dec 2021 at 16:04, Java House <[email protected]> wrote:
>
> Hello
>
> I am trying to build a binary number but I cannot find the correct way:
> 13> <<1:1/bitstring, 0:1/bitstring,0:1/bitstring,0:1/bitstring,0:1/bitstring,0:1/bitstring,0:1/bitstring,0:1/bitstring>>.
> ** exception error: bad argument
>      in function  eval_bits:eval_exp_field1/6 (eval_bits.erl, line 123)
>      in call from eval_bits:create_binary/2 (eval_bits.erl, line 81)
>      in call from eval_bits:expr_grp/4 (eval_bits.erl, line 72)
>
> How do we build a binary number e.g.
> 10000000 or 10101010 or even a binary number that is not just 8 bit but 12, 14 or 17 bit long
>
> Kind Regards
> Nikolas
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.