[erlang-questions] Equal binaries with different integers

zxq9@REDACTED zxq9@REDACTED
Wed May 1 09:34:15 CEST 2019


On 2019年4月29日月曜日 11時21分33秒 JST DOBRO wrote:
> Hi,
> could anyone explain me how is it possible?
>  
> In shell:
>  
> 1> <<24930>> =:= <<98>>.
> true


Your trying to put 24930 into a space that can hold a max value of 255.
If you want that entire value to be represented you have to give it enough ROOM (in terms of bits) to reside there.

Contemplate the following carefully:

1> <<0>>.
<<0>>
2> <<0:8>>.
<<0>>
3> <<0:32>>.
<<0,0,0,0>>
4> <<1:32>>.
<<0,0,0,1>>
5> <<255:32>>.
<<0,0,0,255>>
6> <<256:32>>.
<<0,0,1,0>>
7> <<24930:32>>.
<<0,0,97,98>>
8> <<_:24, 98:8>> = <<24930:32>>.
<<0,0,97,98>>

-Craig



More information about the erlang-questions mailing list