Bit Syntax Problem
Tue Mar 25 08:37:39 CET 2003
Edwin Zacharias writes:
> I'm having a problem with the bit syntax in the
> following function:
> g() ->
> case <<0>> of
> <<0:1, _/binary>> -> true;
> _ -> false
> This should return true, but it returns false when I
> run it. However when I run just the body of the
> function in erl, it returns true. Is there something
> wrong with my function declaration?
The pattern <<0:1, _/binary>> is not allowed; the "unit" for binaries
is 8 bits, which means that the whole expression will be a multiple of
N*8 + 1 bits. That's not allowed.
What you probably want to do is
case <<0>> of
<<0:1, _:7>> -> true;
the compiler could be a little more helpful by giving you a warning,
but it doesn't.
(in particular 6.6, which mentions a case similar to yours)
More information about the erlang-questions