Erlang / Erlang Basics Interview questions
What are binaries/bitstrings in Erlang?
A bitstring is a sequence of raw bits; a binary is the common special case whose length is a multiple of 8 bits (whole bytes). They're the go-to type for network data, files, and any bulk binary payload, written between double angle brackets.
Bin = <<1, 2, 3>>, <<A:8, B:8, Rest/binary>> = Bin. %% A = 1, B = 2, Rest = <<3>>
The bit-syntax pattern above is one of Erlang's standout features: you can match and slice binary protocol fields — fixed widths, variable-length trailing sections, even non-byte-aligned bit widths — directly in a pattern, without manual bit-shifting code.
Binaries over 64 bytes are also reference-counted and stored off the process heap, so passing a large binary between processes doesn't require copying its contents, only the reference.
More Related questions...