[][src]Trait sbitty::ToggleBit

pub trait ToggleBit {
    fn toggle_bit(&self, idx: usize) -> Result<Self, IndexError>
    where
        Self: Sized
; }

performing _ (1 << idx) with n the index

Examples

unset bit for big int

Don't pay attention to my bigint implementation.

pub struct BigInt {
	hwb: i64,
	lwb: i64,
}
impl ToggleBit for BigInt {
	fn toggle_bit(&self, idx: usize) -> Result<Self,IndexError> where Self: Sized {
		if idx >= 128 {
			Err(IndexError)
		} else if idx >= 64 {
			Ok(BigInt{
				hwb: self.hwb ^ (1 << (idx - 64)),
				lwb: self.lwb
			})
		} else {
			Ok(BigInt{
				hwb: self.hwb,
				lwb: self.lwb ^ (1 << (idx - 64))
			})
		}
	}
}

Required methods

fn toggle_bit(&self, idx: usize) -> Result<Self, IndexError> where
    Self: Sized

Loading content...

Implementors

impl ToggleBit for i8[src]

impl ToggleBit for i16[src]

impl ToggleBit for i32[src]

impl ToggleBit for i64[src]

impl ToggleBit for isize[src]

impl ToggleBit for u8[src]

impl ToggleBit for u16[src]

impl ToggleBit for u32[src]

impl ToggleBit for u64[src]

impl ToggleBit for usize[src]

Loading content...