Documentation

Batteries.Data.Int

def Int.testBit :
Int → Nat → Bool

testBit m n returns whether the (n+1) least significant bit is 1 or 0, using the two's complement convention for negative m.

Equations
Instances For
    def Int.ofBits {n : Nat} (f : Fin n → Bool) :

    Construct an integer from a sequence of bits using little endian convention.

    The sign is determined using the two's complement convention: the result is negative if and only if n > 0 and f (n-1) = true.

    Equations
    Instances For
      @[simp]
      theorem Int.ofBits_zero (f : Fin 0 → Bool) :
      ofBits f = 0
      @[simp]
      theorem Int.testBit_ofBits_lt {n i : Nat} {f : Fin n → Bool} (h : i < n) :
      (ofBits f).testBit i = f ⟨i, h⟩
      @[simp]
      theorem Int.testBit_ofBits_ge {n i : Nat} {f : Fin n → Bool} (h : i ≥ n) :
      theorem Int.testBit_ofBits {n i : Nat} (f : Fin n → Bool) :
      (ofBits f).testBit i = if h : i < n then f ⟨i, h⟩ else decide (ofBits f < 0)