[erlang-questions] Offset calculation in bit syntax

Ben Hood 0x6e6562@REDACTED
Mon Nov 26 14:35:46 CET 2007


 > 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. 
  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20071126/053ea3eb/attachment.htm>


More information about the erlang-questions mailing list