Trait GetBit

Source
pub trait GetBit {
    // Required method
    fn get_bit(&self, idx: usize) -> Option<bool>;
}
Expand description

performing _ & (1 << idx) with n the index and return the boolean corresponding

§Examples

§get bit for big int

Don’t pay attention to my bigint implementation.

pub struct BigInt {
	hwb: i64,
	lwb: i64,
}
impl GetBit for BigInt {
	fn get_bit(&self, idx: usize) -> Option<bool> {
		if idx >= 128 {
			None
		} else if idx >= 64 {
			if self.hwb & (1 << (idx - 64)) != 0 {
				Some(true)
			}
			else {
				Some(false)
			}
		} else {
			if self.lwb & (1 << idx) != 0 {
				Some(true)
			}
			else {
				Some(false)
			}
		}
	}
}

Required Methods§

Source

fn get_bit(&self, idx: usize) -> Option<bool>

Implementations on Foreign Types§

Source§

impl GetBit for i8

Source§

fn get_bit(&self, idx: usize) -> Option<bool>

Source§

impl GetBit for i16

Source§

fn get_bit(&self, idx: usize) -> Option<bool>

Source§

impl GetBit for i32

Source§

fn get_bit(&self, idx: usize) -> Option<bool>

Source§

impl GetBit for i64

Source§

fn get_bit(&self, idx: usize) -> Option<bool>

Source§

impl GetBit for isize

Source§

fn get_bit(&self, idx: usize) -> Option<bool>

Source§

impl GetBit for u8

Source§

fn get_bit(&self, idx: usize) -> Option<bool>

Source§

impl GetBit for u16

Source§

fn get_bit(&self, idx: usize) -> Option<bool>

Source§

impl GetBit for u32

Source§

fn get_bit(&self, idx: usize) -> Option<bool>

Source§

impl GetBit for u64

Source§

fn get_bit(&self, idx: usize) -> Option<bool>

Source§

impl GetBit for usize

Source§

fn get_bit(&self, idx: usize) -> Option<bool>

Implementors§