Thank you! I’ve forgotten to write it
I’ll update the article later.
As far as I know integer to bitstring on erlang/elixir is used :binary.encode_unsigned/1. Right?
iex(1)> :binary.encode_unsigned(0b1101_1001)
<<217>>
iex(2)> ~b(1101_1001)
<<217>>
I think most of cases are covered by :binary.encode_unsigned/1
and 0b
literal you mentioned.
It has difference about heading 0
s. 0b
aligns the size as 8bit, ~b
keeps its size.
iex(23)> bit_size(:binary.encode_unsigned(0b000_1000))
8
iex(24)> bit_size(~b(000_1000))
7
That’s I needed.