pub trait BitManipulation {
    fn set_bit(&mut self, bit: usize, bit_val: bool);
    fn test_bit(&self, bit: usize) -> bool;
    fn bit_length(&self) -> usize;
}
Expand description

Bits manipulation in BigInt

Required Methods§

Sets/unsets bit in the number

Example
let mut n = BigInt::from(0b100);
n.set_bit(3, true);
assert_eq!(n, BigInt::from(0b1100));
n.set_bit(0, true);
assert_eq!(n, BigInt::from(0b1101));
n.set_bit(2, false);
assert_eq!(n, BigInt::from(0b1001));

Tests if bit is set

let n = BigInt::from(0b101);
assert_eq!(n.test_bit(3), false);
assert_eq!(n.test_bit(2), true);
assert_eq!(n.test_bit(1), false);
assert_eq!(n.test_bit(0), true);

Length of the number in bits

assert_eq!(BigInt::from(0b1011).bit_length(), 4);

Implementors§