[erlang-questions] surprising integer (external) encoding

Valentin Micic <>
Wed Jul 4 09:12:22 CEST 2007


Observation:

term_to_binary( 16#7FFFFFF ) produces <<131,98,7,255,255,255>>

however
term_to_binary( 16#7FFFFFF )  does *not* produce  <<131,98,8,255,255,255>>
but:
<<131,110,4,0,255,255,255,8>>
whish is encoding for big numbers.

Out of curisosty:

Q1: Why 2^27 values only? It is more intuitive to expect 2^31, and leave 
only one bit (as opposed to 5) for sign (second complement) encoding.
Q2: Big numbers are encoded using little endian encoding, however lengths 
indicating the number are encoded using big-endian (well, this becomes 
obvious only for large enough numbers). Any particular reason? Or is it just 
a question of more Haiku?

V. 




More information about the erlang-questions mailing list