How to you get the length of a binary in bytes? It's not a string. I don't want the number of characters. I just want to know how many bytes long it is.
You could leverage byte_size
for that purpose as documented here
Returns the number of bytes needed to contain bitstring.
That is, if the number of bits in bitstring is not divisible by 8, the resulting number of bytes will be rounded up (by excess). This operation happens in constant time.
Allowed in guard tests. Inlined by the compiler.
Examples
iex> byte_size(<<433::16, 3::3>>) 3
iex> byte_size(<<1, 2, 3>>)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With