To understand binaries, you need to know what bit-strings are.
Bit-strings represent a contiguous sequence of bits in memory. The syntax used to denote a bit-string is <<>>
. ::n
can be used to specify the number of bits used to represent a single
A binary is a bit-string whose number of bits is divisible by 8.
To check whether the given bit-sequence is a binary or not, we can use the is_binary
method:
IO.puts(is_bitstring("edpresso"))# output: trueIO.puts(is_bitstring("edpresso"))#output: trueIO.puts(is_bitstring(<<64::16, 128::72, 256::80>>))#output: trueIO.puts(is_binary(<<64::16, 128::72, 256::80>>))#output: trueIO.puts(is_bitstring(<<64::17, 128::73, 256::81>>))#output: trueIO.puts(is_binary(<<64::17, 128::73, 256::81>>))#output: false
Since all strings are binary, using
is_binary
might be useful when you want to distinguish whether or not the input or return value is a string.
Free Resources