Binary construction

Per Gustafsson per.gustafsson@REDACTED
Fri Feb 24 15:00:13 CET 2006


Hi

It's because when binaries are constructed from integers and there is an 
integer that is larger than the number of bits in the segment the low 
bits of the integer are put into the binary.

i.e <<X:16>> works the same as << (16#ffff band X) : 16 >>.

Per

chandru wrote:
> Hi,
> 
> 23> <<1:16>>.
> <<0,1>>
> 24> <<21:16>>.
> <<0,21>>
> 25> <<321:16>>.
> <<1,65>>
> 26> <<4321:16>>.
> <<16,225>>
> 27> <<54321:16>>.
> <<212,49>>
> 28> <<654321:16>>.
> <<251,241>>
> 29> <<7654321:16>>.
> <<203,177>>
> 30> <<87654321:16>>.
> <<127,177>>
> 
> Why are the resulting binaries all different? I thought that if I gave
> a value of more than 65535 and asked for it to be packed into 16 bits,
> I would always get <<255,255>>. Why is it not?
> 
> cheers
> Chandru




More information about the erlang-questions mailing list