Re: creating a binary number

Leonard B <[email protected]>
Newsgroups gmane.comp.lang.erlang.general
Message-ID <CAKj1m=Lnf0pWguCyhZhOMRMkrRD=Tm9Z4KvuRuNuAC4KRLkyCw@mail.gmail.com>
Depending on what you're actually trying to do you could maybe use
binary_to_integer/2 and integer_to_binary/2

3> binary_to_integer(<<"11111111">>,2).
255
4> integer_to_binary(255,2).
<<"11111111">>

Leonard

On Thu, Dec 9, 2021 at 12:47 PM Java House <[email protected]> wrote:
>
> Hi Jacob
> I tried it but it does not work
>
> 16> Z = <<<<1>>:1/bitstring,<<1>>:1/bitstring,<<1>>:1/bitstring,<<1>>:1/bitstring,<<1>>:1/bitstring,<<1>>:1/bitstring,<<1>>:1/bitstring,<<1>>:1/bitstring>>.
> <<0>>
> 17> Z.
> <<0>>
>
> I should be getting back <<255>> but I get back 0.
>
>
> Στις Πέμ 9 Δεκ 2021 στις 5:17 μ.μ., ο/η Jacob <[email protected]> έγραψε:
>>
>> On 12/9/21 5:04 PM, Java House 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>>.
>>
>> It's either << <<1>>:1/bitstring >> or << 1:1 >> (for one bit).
>>
>> Jacob
>>
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.