[][src]Trait sbitty::GetBit

pub trait GetBit {
    pub fn get_bit(&self, idx: usize) -> Option<bool>;
}

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

pub fn get_bit(&self, idx: usize) -> Option<bool>[src]

Loading content...

Implementors

impl GetBit for i8[src]

impl GetBit for i16[src]

impl GetBit for i32[src]

impl GetBit for i64[src]

impl GetBit for isize[src]

impl GetBit for u8[src]

impl GetBit for u16[src]

impl GetBit for u32[src]

impl GetBit for u64[src]

impl GetBit for usize[src]

Loading content...