[erlang-questions] Padding a binary to a multiple of 4 bytes

Camille Troillard tuscland@REDACTED
Sun Dec 21 13:24:15 CET 2008


Thank you Matthew and everybody who responded for all these suggestions.

On Sun, Dec 21, 2008 at 4:24 AM, Matthew Dempsky <matthew@REDACTED>wrote:

> 2008/12/20 Camille Troillard <tuscland@REDACTED>:
> > I don't find it very elegant, and guess there is a better way of doing
> this.
>
> Your solution looks fine to me.
>
> > Also, I was wondering why the "/binary" suffix was needed if I want to
> > append to the Bin variable.  Intuitively, I have written <<Bin, 0:size>>,
> > but it doesn't work.
>
> If you omit a type specifier on a variable in a binary expression, it
> defaults to a single byte.  The expression is statically typed at
> compile time, so if you write <<Bin>>, the compiler writes code that
> assumes Bin is an integer value.  At run-time, when it detects it's a
> binary instead, a type error is raised.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20081221/62337023/attachment.htm>


More information about the erlang-questions mailing list