Integer endianness in binaries
Gleb Peregud
gleber.p@REDACTED
Wed Feb 17 23:06:34 CET 2010
Hello.
These
[0,0,0,0,0,0,0,1] = [ X || <<X:1>> <= <<1>> ].
[0,0,0,0,0,0,1,0] = [ X || <<X:1>> <= <<2>> ].
[0,0,0,0,0,0,1,1] = [ X || <<X:1>> <= <<3>> ].
[0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0] = [ X || <<X:1>> <=
<<15:2/little-integer-unit:8>> ].
are true and does not fail. But this:
> [0,0,0,1,1,1,1,0,0,0,0,0,0,0] = [ X || <<X:1>> <= <<15:2/little-integer-unit:7>> ].
** exception error: no match of right hand side value
[0,0,0,0,1,1,1,1,0,0,0,0,0,0]
fails with given badmatch. Why is it so? Am I missing something?
Shouldn't <<15:2/little-integer-unit:7>> be the same as <<15:7, 0:7>>
? Instead it is equal to <<15:8, 0:6>>.
Best regards,
Gleb
--
Gleb Peregud
Green Elephant Labs
More information about the erlang-questions
mailing list