Bit arrays

Bit arrays represent a sequence of 1s and 0s, and are a convenient syntax for constructing and manipulating binary data.

Each segment of a bit array can be given options to specify the representation used for that segment.

  • size: the size of the segment in bits.
  • unit: the number of bits that the size value is a multiple of.
  • bits: a nested bit array of any size.
  • bytes: a nested byte-aligned bit array.
  • float: a 64 bits floating point number.
  • int: an int with a default size of 8 bits.
  • big: big endian.
  • little: little endian.
  • native: the endianness of the processor.
  • utf8: utf8 encoded text.
  • utf16: utf16 encoded text.
  • utf32: utf32 encoded text.
  • utf8_codepoint: a utf8 codepoint.
  • utf16_codepoint: a utf16 codepoint.
  • utf32_codepoint: a utf32 codepoint.
  • signed: a signed number.
  • unsigned: an unsigned number.

Multiple options can be given to a segment by separating each with a dash: x:unsigned-little-size(2).

Bit arrays have limited support when compiling to JavaScript, not all options can be used. Full bit array support will be implemented in the future.

For more information on bit arrays see the Erlang bit syntax documentation.