Erlang Language

Bit Syntax: Defaults

Introduction#

The Erlang doc titled Bit Syntax has a section called Defaults that contains an error and the doc is confusing as a whole. I rewrote it.

Defaults explained

4.4 Defaults


The default Size depends on the type. For integer it is 8. For float it is 64. For binary it is the size of the specified binary:

1> Bin = << 17/integer, 3.2/float, <<97, 98, 99>>/binary >>. 
<<17,64,9,153,153,153,153,153,154,97,98,99>>

2> size(Bin). % Returns the number of bytes:
12            % 8 bits + 64 bits + 3*8 bits = 96 bits => 96/8 = 12 bytes

In matching, a binary segment without a Size is only allowed at t


This modified text is an extract of the original Stack Overflow Documentation created by the contributors and released under CC BY-SA 3.0 This website is not affiliated with Stack Overflow