Pfx.bits
You're seeing just the function
bits
, go back to Pfx module for more information.
Specs
Return the concatenation of 1 or more series of bits of the given pfx
.
Example
iex> bits(%Pfx{bits: <<1, 2, 3, 4>>, maxlen: 32}, [{0,8}, {-1, -8}])
<<1, 4>>
iex> bits({{1, 2, 3, 4}, 32}, [{0,8}, {-1, -8}])
<<1, 4>>
iex> bits({1, 2, 3, 4}, [{0, 8}, {-1, -8}])
<<1, 4>>
iex> bits("1.2.3.4", [{0, 8}, {-1, -8}])
<<1, 4>>
iex> bits("1.2.3.4/24", [{0, 8}, {-1, -8}])
<<1, 0>>
Specs
Return a series of bits for given pfx
, starting bit position
& length
.
Negative position
's are relative to the end of the pfx.bits
bitstring,
while negative length
will collect bits going left instead of to the
right. Note that the bit at given position
is always included in the
result regardless of direction. Finally, a length
of 0
results in
an empty bitstring.
Examples
# first byte
iex> bits(%Pfx{bits: <<128, 0, 0, 1>>, maxlen: 32}, 0, 8)
<<128>>
# same as
iex> bits(%Pfx{bits: <<128, 0, 0, 1>>, maxlen: 32}, 7, -8)
<<128>>
# last two bytes
iex> bits("128.0.128.1", 16, 16)
<<128, 1>>
iex> bits({128, 0, 128, 1}, 16, 16) # same
<<128, 1>>
iex> bits({128, 0, 128, 1}, 31, -16) # same
<<128, 1>>
iex> bits({{128, 0, 128, 1}, 32}, 31, -16) # same
<<128, 1>>
# missing bits are filled in as `0`
iex> x = new(<<128>>, 32)
iex> bits(x, 0, 32)
<<128, 0, 0, 0>>
iex> x = new(<<128>>, 32)
iex> bits(x, 0, 16)
<<128, 0>>
iex> x = new(<<128>>, 32)
iex> bits(x, 15, -16)
<<128, 0>>
# the last 5 bits
iex> x = new(<<255>>, 32)
iex> bits(x, 7, -5)
<<0b11111::size(5)>>