Bit operations on natural numbers #
Naming convention:
- ..._getBit_1 or _eq_one : the value of getBit is 1 at the specified bit(s)
- getBit_of_... : the value of getBit is the value of the specified bit(s), under some preconditions
Returns the k-th least significant bit of a natural number n as a natural number (in {0, 1}).
We decompose each number j < 2^ℓ into its binary representation : j = Σ k ∈ Fin ℓ, jₖ * 2ᵏ
Instances For
Get the numLowBits least significant bits of n.
Instances For
theorem
Nat.getBit_repr_unique
{ℓ j : ℕ}
(h_j : j < 2 ^ ℓ)
(c : ℕ → ℕ)
(h_bin : ∀ k < ℓ, c k = 0 ∨ c k = 1)
(h_sum : j = ∑ k ∈ Finset.Icc 0 (ℓ - 1), c k * 2 ^ k)
(k : ℕ)
:
The binary representation of a number via getBit is unique: any sequence of
0/1 coefficients that sums to j must agree with getBit at each position.
This takes a argument for the number of lowBitss to remove from the number
Instances For
Middle bits: take len bits starting at offset from n.
Instances For
Middle bits are strictly less than 2^len.
Middle bits as a modulus form.