bit syntax documentation

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

bit syntax documentation

Ulf Wiger-4

In the documentation for the bit syntax, I read the following:


"A segment of type binary must have a size evenly divisible by 8.

     This means that the following head will never match:

     foo(<<X:7/binary,Y:1/binary>>) ->"

(http://www.erlang.org/doc/r7b/doc/extensions/bit_syntax.html#6.6)

Since my code didn't work as expected, I tried to verify this:



30> F = fun(<<X:7/binary,Y:1/binary>>) -> {X,Y}; (Other) -> Other
end.
#Fun<erl_eval.17.63972567>
31> F(<<"12345678">>).                                                    
{<<49,50,51,52,53,54,55>>,<<56>>}



In other words, the head described in the manual matches just fine.

Comments?

/Uffe
--
Ulf Wiger                                    tfn: +46  8 719 81 95
Senior System Architect                      mob: +46 70 519 81 95
Strategic Product & System Management    ATM Multiservice Networks
Data Backbone & Optical Services Division      Ericsson Telecom AB



Reply | Threaded
Open this post in threaded view
|

bit syntax documentation

Björn Gustavsson-3
Thanks for pointing out the error.

The head should have been

  foo(<<X:7/binary-unit:1,Y:1/binary-unit:1>>) ->

We will correct the documentation in the R8 release.

/Bjorn

Ulf Wiger <etxuwig> writes:

> In the documentation for the bit syntax, I read the following:
>
>
> "A segment of type binary must have a size evenly divisible by 8.
>
>      This means that the following head will never match:
>
>      foo(<<X:7/binary,Y:1/binary>>) ->"
>
> (http://www.erlang.org/doc/r7b/doc/extensions/bit_syntax.html#6.6)
>
> Since my code didn't work as expected, I tried to verify this:
>
>
>
> 30> F = fun(<<X:7/binary,Y:1/binary>>) -> {X,Y}; (Other) -> Other
> end.
> #Fun<erl_eval.17.63972567>
> 31> F(<<"12345678">>).                                                    
> {<<49,50,51,52,53,54,55>>,<<56>>}
>
>
>
> In other words, the head described in the manual matches just fine.
>
> Comments?
>
> /Uffe
> --
> Ulf Wiger                                    tfn: +46  8 719 81 95
> Senior System Architect                      mob: +46 70 519 81 95
> Strategic Product & System Management    ATM Multiservice Networks
> Data Backbone & Optical Services Division      Ericsson Telecom AB
>

--
Bj?rn Gustavsson            Ericsson Utvecklings AB
bjorn      ?T2/UAB/F/P
                            BOX 1505
+46 8 727 56 87    125 25 ?lvsj?


Reply | Threaded
Open this post in threaded view
|

bit syntax documentation

Robert Virding-4
Bjorn Gustavsson <bjorn> writes:
>Thanks for pointing out the error.
>
>The head should have been
>
>  foo(<<X:7/binary-unit:1,Y:1/binary-unit:1>>) ->
>
>We will correct the documentation in the R8 release.

The default unit for binaries is 8, i.e. bytes.  For integers and
floats the default unit is 1.

        Robert