# [erlang-questions] Bit syntax

Bob Ippolito <>
Wed Mar 9 16:17:34 CET 2011

```8*51 is 408 (which is by coincidence the same as the number of bits),
16#00 is 0. Either way you're extending it to 408 bits.

You're getting a bad match presumably because A, B, and/or C are
already bound in your shell. Do an f(). first to forget all of the
bound variables in the shell, and then it will work.

1> <<A:24, B:48, C:408>> = <<16#effe02:24,16#00:48,16#00:408>>.
<<239,254,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,...>>
2> {A, B, C}.
{15728130,0,0}

On Wed, Mar 9, 2011 at 7:09 AM, Bob Cowdery <> wrote:
> What I actually want is 51 bytes of 16#00.
>
> 12> <<A:24, B:48, C:408>> = <<16#effe02:24,16#00:48,16#00:408>>.
> ** exception error: no match of right hand side value
>
> <<239,254,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
>                      0,0,0,...>>
>
> Why is this different. Isn't it just saying 00 as a 408 bit number
> rather than (8*51)?
>
> Bob
>
> On 09/03/2011 14:55, Vlad Dumitrescu wrote:
>> Your C is 8*51 as a 408 bit number. You probably want 16#00:408 instead.
>>
>>
>> On Wed, Mar 9, 2011 at 15:50, Bob Cowdery <
>> <mailto:>> wrote:
>>
>>     Thanks. The syntax did look a bit odd for a repeating group. I
>>     pulled it
>>     off the web somewhere.
>>
>>     So if I say:
>>
>>     7> <<A:24, B:48, C:408>> = <<16#effe02:24,16#00:48,(8*51):408>>
>>     .
>>     <<239,254,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
>>      0,0,0,...>>
>>     8> A.
>>     15728130
>>     9> B.
>>     0
>>     10> C.
>>     408
>>
>>     What do these bound values mean. C is supposed to be 51 zero bytes
>>     (408
>>     bits). Why is C bound to the number of bits.
>>
>>     Bob
>>
>>     On 09/03/2011 14:29, Vlad Dumitrescu wrote:
>>     > Hi!
>>     >
>>     > On Wed, Mar 9, 2011 at 15:21, Bob Cowdery
>>     < <mailto:>
>>     > <mailto:
>>     <mailto:>>> wrote:
>>     >
>>     >     Hi
>>     >
>>     >     I'm clearly not understanding the bit syntax properly. Could
>>     someone
>>     >     explain to me what I am doing wrong here. Why does the first
>>     not match
>>     >     when its the right shape but the second does when its the
>>     wrong shape.
>>     >     The bound values don't make much sense to me either.
>>     >
>>     >     1> <<A:24, B:48, C:408>> =
>>     <<16#effe02:24,16#00:48,16#00,(8*51):408>>.
>>     >     ** exception error: no match of right hand side value
>>     >
>>     >
>>     > There is an "extra" 16#00 on the right side that is not matched
>>     on the
>>     > left.
>>     >
>>     >
>>     >     2> <<A:32, B:48, C:408>> =
>>     <<16#effe02:24,16#00:48,16#00,(8*51):408>>.
>>     >
>>     >
>>     > The larger size for A "swallows" the extra value, but shifts the
>>     > values a byte to the right.
>>     >
>>     > regards,