/// Bit operations on `Int` (ADR 0035), for binary formats, hashes, masks /// and random generators. /// /// int.and(0b1100, 0b1010) // 8 /// int.shift_left(1, 64) // 18446744073709551616 (a big integer) /// int.shift_right(-5, 1) // -3 (rounds towards minus infinity) /// /// An `Int` behaves as two's complement with infinite sign extension, as in /// Python: `-1` is all ones, so `int.and(n, -1) == n` and `int.not(n)` is /// `-n - 1`. The result is the same whether an operand is small or a big /// integer. A mask above 62 bits can't be a literal (literals are 63-bit): /// compute it, `int.shift_left(1, 64) - 1`. For wrapping 64-bit arithmetic, /// see `std/u64`. /// The bits set in both. @extern c "tl_int_and" pub fn and :: a: Int b: Int -> Int /// The bits set in either. @extern c "tl_int_or" pub fn or :: a: Int b: Int -> Int /// The bits set in exactly one. @extern c "tl_int_xor" pub fn xor :: a: Int b: Int -> Int /// Every bit flipped: `-n - 1`. @extern c "tl_int_not" pub fn not :: n: Int -> Int /// `n * 2^k`. Panics if `k` is negative, or if it is `2^32` or more and `n` /// is not 0 (the result would not fit in memory). @extern c "tl_int_shift_left" pub fn shift_left :: n: Int k: Int -> Int /// `n / 2^k`, rounded towards minus infinity: `shift_right(-1, k)` is `-1`. /// Panics if `k` is negative. @extern c "tl_int_shift_right" pub fn shift_right :: n: Int k: Int -> Int /// The number of bits of `|n|`: 0 for 0, 1 for 1 and -1, 8 for 255. @extern c "tl_int_bit_length" pub fn bit_length :: n: Int -> Int /// Whether bit `k` (0 is the lowest) of `n` is set. pub fn bit :: n: Int k: Int -> Bool { and (shift_right n k) 1 == 1 } /// The low `bits` bits of `n`: `n` modulo `2^bits`, in `[0, 2^bits)`. pub fn low_bits :: n: Int bits: Int -> Int { and n (shift_left 1 bits - 1) }