0 bis 255 darstellen0x00 bis 0xFF.<<>> definiert.
255 verwendest, werden nur die letzten 8 Bits verwendet, es sei denn, du gibst mit dem ::-Operator die zu verwendende Einheit und/oder Größe an.<>/2 kannst du Bitstrings/Binaries/Strings verketten.<<255>> == <<0xFF>>
# Overflowing bits are truncated
<<256>> == <<0>>
<<256::size(16)>> == <<1, 0>>
<<"Hello">> == <<72, 101, 108, 108, 111>>
Ein Nullbyte ist ein anderer Name für <<0>>.
# This string has a string length of 5, but is made up of 7 bytes
string = "cześć"
String.length(string) != byte_size(string)
# Even emoji strings are encoded binaries
"👍" == <<240, 159, 145, 141>>
# Ignore the first 8 bytes, bind the remaining variable sized binary to `body`
<<_::binary-size(8), body::binary>>
Das funktioniert auch mit Strings:
# bind the first 5 bytes to `name`,
# match the string literal " the ",
# bind remaining bytes to `species`
<<name::binary-size(5), " the ", species::binary>> = <<"Frank the Walrus">>
{name, species}
# => {"Frank", "Walrus"}