Binaries
Binaries are written and printed as sequences of integers or strings, enclosed in double less-than and greater-than brackets. Here’s an example:
| | 1> <<5,10,20>>. |
| | <<5,10,20>> |
| | 2> <<"hello">>. |
| | <<"hello">> |
| | 3> <<65,66,67>>. |
| | <<"ABC">> |
When you use integers in a binary, each must be in the range
0 to 255. The binary
<<"cat">> is shorthand for
<<99,97,116>>; that is, the binary is made
from the ASCII character codes of the characters in the string.
As with strings, if the content of a binary is a printable string, then the shell will print the binary as a string; otherwise, it will be printed as a sequence of integers.
We can build a binary and extract the elements of a binary using a BIF, or we can use the bit syntax (see ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access