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

Kostis Sagonas <>
Fri Mar 8 09:41:00 CET 2013


On 03/08/2013 09:30 AM, Max Lapshin wrote:
> 0:Pad
>
> Pad can be zero-length.

For people like me who are a bit slow, can you please explain how this 
is possible in the code below?

Kostis

> On Fri, Mar 8, 2013 at 12:32 PM, Kostis Sagonas <
> <mailto:>> wrote:
>
>     On 03/08/2013 08:58 AM, Ulf Wiger wrote:
>
>
>         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>>.
>
>
>     I fail to see where this creates a 0-sized integer...
>
>     Kostis
>
>     _________________________________________________
>     erlang-questions mailing list
>      <mailto:>
>     http://erlang.org/mailman/__listinfo/erlang-questions
>     <http://erlang.org/mailman/listinfo/erlang-questions>
>
>




More information about the erlang-questions mailing list