[erlang-bugs] Documentation request: integer encoding and truncation

Edwin Fine <>
Fri Aug 22 19:09:30 CEST 2008


I refer to the following post. I was caught unawares by this apparently
undocumented behavior.

http://www.erlang.org/pipermail/erlang-questions/2007-July/027657.html

May I strongly recommend placing this information (taken from the above
post) in the Erlang Reference Manual, in the section on binaries. It may
save other people time and confusion. A further question is whether or not
this *should* be the behavior. As a language used for writing highly
reliable systems, shouldn't this overflow condition be caught? Maybe as an
optional run-time flag?

Integer Encoding and Truncation

<<I:N>>

is equivalent to

<<(I band ((1 bsl N) - 1)):N>>

That is, if the integer I can not be represented in N bits, the low N bits
of the integer is put into the binary.

Binaries work in a similar manner e.g.

1> <<1,2>> = << (<<1,2,3>>):2/binary >>.
<<1,2>>

Regards,
Edwin Fine
-- 
For every expert there is an equal and opposite expert - Arthur C. Clarke
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-bugs/attachments/20080822/fbb582a0/attachment.html>


More information about the erlang-bugs mailing list