[erlang-questions] bit syntax: what does "<<1234>> =" match?

Anthony Ramine <>
Sat Feb 26 15:24:39 CET 2011


Le 25 févr. 2011 à 20:23, Anton Lebedevich a écrit :

> Hello,
> 
> In erlang R14B01 shell:
> 1> <<1234>> = <<1234>>.
> ** exception error: no match of right hand side value <<"Ò">>
> 
> Right side of expression evaluates to <<210>> (8 least significant bits
> from 1234), so the following matches:
> 2> <<210>> = <<1234>>.
> <<"Ò">>
> 
> 1234 on the left side of expression should evaluate to <<210>> too, but
> it doesn't:
> 3> <<1234>> = <<210>>.
> ** exception error: no match of right hand side value <<"Ò">>
> 
> Is there an explanation of what happens when integer on left side of
> binary matching expression doesn't fit into default 8 bit?
> 
> Regards,
> Anton Lebedevich.

Wild guess here, but I would say <<1234>> on the right side constructs a binary using the use-only-the-8-least-significant-bits, thus not failing because the integer is too large; while <<1234>> on the left side is a pattern, so the integer isn't truncated and obviously fails to match since you can't have a byte larger than 255.

Regards,

--
Anthony Ramine
Dev:Extend
http://dev-extend.eu



More information about the erlang-questions mailing list