Pfx.bit

You're seeing just the function bit, go back to Pfx module for more information.

Specs

bit(prefix(), integer()) :: 0 | 1

Returns the bit-value at given position in pfx.

A bit position is a 0-based index from the left with range 0..maxlen-1. A negative bit position is taken relative to Pfx.maxlen. Bits that are masked (bit position in the range of bit_size(pfx.bits) .. pfx.maxlen - 1) always yield 0.

Examples

iex> bit("1.2.0.0", 14)
1

# same bit
iex> bit("1.2.0.0", -18)
1

iex> bit("1.2.0.0/16", 14)
1

iex> bit({1, 2, 0, 0}, 14)
1

iex> bit({{1, 2, 0, 0}, 16}, 14)
1

iex> bit(%Pfx{bits: <<1, 2>>, maxlen: 32}, 14)
1

# 'masked' bits are deemed to be `0`
iex> bit("1.2.0.0/16", 24)
0

# errors out on invalid positions
iex> bit("255.255.255.255", 33)
** (ArgumentError) invalid bit position: 33

iex> bit("10.10.0.0/16", -33)
** (ArgumentError) invalid bit position: -33