zero length segments!
Chandrashekhar Mullaparthi
Chandrashekhar.Mullaparthi@REDACTED
Tue Sep 24 16:35:14 CEST 2002
I've had the same problem. You have to do
Var = 31 - Bit,
<<_:Var, Flag:1, _:(Bit)>> = <<1:32>>,
cheers
Chandru
-----Original Message-----
From: Vance Shipley [mailto:vances@REDACTED]
Sent: 24 September 2002 15:03
To: erlang-questions@REDACTED
Subject: Re: zero length segments!
Well didn't I speak too soon! While this works wonderfully in the shell
it won't complile. :(
Eshell V5.1.2 (abort with ^G)
1> T = fun(Bit) -> <<_:(31 - Bit), Flag:1, _:(Bit)>> = <<1:32>>, Flag end.
#Fun<erl_eval.5.63972567>
2> T(0).
1
3> T(1).
0
-module(t).
-export([t/1]).
t(Bit) when integer(Bit) ->
<<_:(31 - Bit), Flag:1, _:(Bit)>> = <<1:32>>,
Flag.
1> c(t).
./t.erl:5: illegal bit size
error
The problem seems to be with the expression (31 - Bit).
Any idea how to get past this?
-Vance
Vance Shipley
Motivity Telecom Inc.
+1 519 579 5816
vances@REDACTED
On Tue, Sep 24, 2002 at 06:33:23AM -0400, Vance Shipley wrote:
>
> Was I ever happily suprised when I found that this was a valid expression:
>
> <<0:8, 1:24, 0:0>>
>
> It results in:
>
> <<0,0,0,1>>
>
> The reason this is so good is that it I don't have to handle a special
> case when X=0:
>
> Flag = <<_:(31-X), Flag:1, _:(X)>>
>
> Of course I'm sure that that is why it works, I'm just very happy about
it. :)
>
> -Vance
NOTICE AND DISCLAIMER:
This email (including attachments) is confidential. If you have received
this email in error please notify the sender immediately and delete this
email from your system without copying or disseminating it or placing any
reliance upon its contents. We cannot accept liability for any breaches of
confidence arising through use of email. Any opinions expressed in this
email (including attachments) are those of the author and do not necessarily
reflect our opinions. We will not accept responsibility for any commitments
made by our employees outside the scope of our business. We do not warrant
the accuracy or completeness of such information.
More information about the erlang-questions
mailing list