[erlang-questions] surprising bit syntax
Ulf Wiger
ulf@REDACTED
Tue Jul 3 15:49:08 CEST 2007
Well, I was just goofing around with term comparisons, and
came across something unexpected. It's logical, of course,
but it should be documented.
BR,
Ulf W
2007/7/3, Matthew O'Gorman <mogorman@REDACTED>:
> 8 bits you pump in 999 which would be 03 E7, so what happens e7 rolls
> over 3 times so e7 in decimal is nnananna = 231. what you would need
> to do is make <<I:8/integer>> is <<I:16/integer>>
>
> hope this helps
>
> mog
>
> On 7/3/07, Dmitrii 'Mamut' Dimandt <dmitriid@REDACTED> wrote:
> >
> > Ulf Wiger (TN/EAB) wrote:
> >
> >
> >
> > Is it just me, or is this behaviour surprising?
> >
> > 4> <<255>>.
> > <<"ÿ">>
> > 5> <<256>>.
> > <<0>>
> > 6> <<257>>.
> > <<1>>
> > 7> <<257:8>>.
> > <<1>>
> > 8> <<I:8/integer>> = <<999>>.
> > <<"ç">>
> > 9> I.
> > 231
> >
> > I scanned the reference manual to find a note stating that this
> > is exactly what one should expect, but I couldn't find it.
> >
> > Personally, I would have expected something along the lines
> > of badarg, which is what list_to_binary([999]) gives. My results are
> > consistent with yours:
> >
> > 1> <<255>>.
> > <<"\377">>
> > 2> <<256>>.
> > <<0>>
> > 3> <<257>>.
> > <<1>>
> > 4> <<257:8>>.
> > <<1>>
> > 5> <<I:8/integer>> = <<999>>.
> > <<"\347">>
> > 6> I.
> > 231
> >
> >
> >
> >
> > _______________________________________________
> > erlang-questions mailing list
> > erlang-questions@REDACTED
> > http://www.erlang.org/mailman/listinfo/erlang-questions
> >
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>
More information about the erlang-questions
mailing list