[erlang-questions] Padding a binary to a multiple of 4 bytes
Sun Dec 21 04:24:34 CET 2008
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.
More information about the erlang-questions