[erlang-questions] sub-byte endianness in bit syntax

Michael McDaniel erlangx@REDACTED
Thu Aug 16 21:46:30 CEST 2007


On Thu, Aug 16, 2007 at 06:54:03PM +0100, Tony Finch wrote:
> On Wed, 15 Aug 2007, Bob Ippolito wrote:
> 
> > It takes a few seconds to figure this out yourself:
> >
> > 1> <<A:2/little, B:2/big, _:4>> = <<2#10100000>>, {A, B}.
> > {2,2}
> 
> It would be nice if this were documented.
> 
> How do you tell Erlang to fill bytes little-end first?
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

 documentation, programming examples, section 4.3

"
 The TypeSpecifierList is a list of type specifiers separated by hyphens.

Type
    The type can be integer, float, or binary. 
Signedness
    The signedness specification can be either signed or unsigned. Note that
     signedness only matters for matching. 
Endianness
    The endianness specification can be either big, little, or native. Native-endian
    means that the endian will be resolved at load time to be either big-endian or
    little-endian, depending on what is "native" for the CPU that the Erlang
    machine is run on. 
Unit
    The unit size is given as unit:IntegerLiteral. The allowed range is 1-256. It
    will be multiplied by the Size specifier to give the effective size of the
    segment. 

Example:

X:4/little-signed-integer-unit:8
    

This element has a total size of 4*8 = 32 bits, and it contains a signed integer
in little-endian order.
"

~Michael



> 
> Tony.
> -- 
> f.a.n.finch  <dot@REDACTED>  http://dotat.at/
> IRISH SEA: SOUTHERLY, BACKING NORTHEASTERLY FOR A TIME, 3 OR 4. SLIGHT OR
> MODERATE. SHOWERS. MODERATE OR GOOD, OCCASIONALLY POOR.
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
> 
> !DSPAM:52,46c48f8773321070549924!
> 
> 

-- 
Michael McDaniel
Portland, Oregon, USA
http://autosys.us
+1 503 283 5284



More information about the erlang-questions mailing list