bitops

Bit Manipulation Utilities

Functions

FunctionDescription
bit_pow2Internal: power of 2 lookup.
bit_shlLeft shift: a « n.
bit_shrLogical right shift: a »> n (unsigned).
bit_andBitwise AND via arithmetic decomposition.
bit_orBitwise OR via arithmetic decomposition.
bit_xorBitwise XOR via arithmetic decomposition.
bit_notBitwise NOT (ones complement, 64-bit).
bit_getGet bit n of a (0 or 1).
bit_setSet bit n of a to 1.
bit_clearClear bit n of a to 0.
bit_toggleToggle bit n of a.
bit_countPopulation count (number of 1 bits).
bit_leading_zerosNumber of leading zero bits (from MSB).
bit_trailing_zerosNumber of trailing zero bits (from LSB).
bit_reverseReverse bit order.
bit_rotlRotate left by n positions.
bit_rotrRotate right by n positions.

Details

bit_pow2

fn bit_pow2(n: i64) -> i64

Internal: power of 2 lookup.

bit_shl

fn bit_shl(a: i64, n: i64) -> i64

Left shift: a « n.

bit_shr

fn bit_shr(a: i64, n: i64) -> i64

Logical right shift: a »> n (unsigned).

bit_and

fn bit_and(a: i64, b: i64) -> i64

Bitwise AND via arithmetic decomposition.

bit_or

fn bit_or(a: i64, b: i64) -> i64

Bitwise OR via arithmetic decomposition.

bit_xor

fn bit_xor(a: i64, b: i64) -> i64

Bitwise XOR via arithmetic decomposition.

bit_not

fn bit_not(a: i64) -> i64

Bitwise NOT (ones complement, 64-bit).

bit_get

fn bit_get(a: i64, n: i64) -> i64

Get bit n of a (0 or 1).

bit_set

fn bit_set(a: i64, n: i64) -> i64

Set bit n of a to 1.

bit_clear

fn bit_clear(a: i64, n: i64) -> i64

Clear bit n of a to 0.

bit_toggle

fn bit_toggle(a: i64, n: i64) -> i64

Toggle bit n of a.

bit_count

fn bit_count(a: i64) -> i64

Population count (number of 1 bits).

bit_leading_zeros

fn bit_leading_zeros(a: i64) -> i64

Number of leading zero bits (from MSB).

bit_trailing_zeros

fn bit_trailing_zeros(a: i64) -> i64

Number of trailing zero bits (from LSB).

bit_reverse

fn bit_reverse(a: i64) -> i64

Reverse bit order.

bit_rotl

fn bit_rotl(a: i64, n: i64) -> i64

Rotate left by n positions.

bit_rotr

fn bit_rotr(a: i64, n: i64) -> i64

Rotate right by n positions.