[erlang-questions] Offset calculation in bit syntax

Hynek Vychodil <>
Mon Nov 26 16:33:16 CET 2007


No, it's not allowed in R11B, but in R12B may be.

On 11/26/07, Ben Hood <> wrote:
> > There is bug in your code I think.
> >
> > Correct code should be:
> >
> > decode(<<L:8/unsigned, R/binary>>) ->
> > Len = (L - 16#20)*8,
> > <<Rest:Len/unsigned, _/binary>> = R,
> > Rest.
>
> That's how I ended solving it, but there was also a bug in the way I
> specified the problem, what I was attempting to ask was whether something
> this was possible:
>
>
> decode(<<L:8,Bin:(L - 16#20)/binary,Rest/binary>>) -> Bin.
>
> So decode(<<16#23,"abcdefg">>) would return <<"abc">>.
>
> Essentially this is the same thing as your solution, only expressed in a
> more compact format. However, it doesn't appear to be a legal operation in
> Erlang bit syntax.
> _______________________________________________
> erlang-questions mailing list
> 
> http://www.erlang.org/mailman/listinfo/erlang-questions
>


-- 
--Hynek (Pichi) Vychodil



More information about the erlang-questions mailing list