[erlang-questions] bit syntax: 0-sized segments

Ulf Wiger ulf@REDACTED
Fri Mar 8 08:58:42 CET 2013


On 8 Mar 2013, at 08:38, Dan Gudmundsson wrote:

> Another nice thing with 0 sized integers is when you add alignment
> bits in protocols, in both
> matching and creation.

I make use of this in sext as well, in a number of places:

encode_bin_elems(<<>>) ->
    <<8>>;
encode_bin_elems(B) ->
    Pad = 8 - (size(B) rem 8),
    << (<< <<1:1, B1:8>> || <<B1>> <= B >>)/bitstring, 0:Pad, 8 >>.

BR,
Ulf W

Ulf Wiger, Co-founder & Developer Advocate, Feuerlabs Inc.
http://feuerlabs.com






More information about the erlang-questions mailing list