Trait std::num::Bitwise
pub trait Bitwise: Bounded + Not<Self> + BitAnd<Self, Self> + BitOr<Self, Self> + BitXor<Self, Self> + Shl<Self, Self> + Shr<Self, Self> { fn count_ones(&self) -> Self; fn leading_zeros(&self) -> Self; fn trailing_zeros(&self) -> Self; fn count_zeros(&self) -> Self { ... } }
Numbers with a fixed binary representation.
Required Methods
fn count_ones(&self) -> Self
Returns the number of ones in the binary representation of the number.
Example
use std::num::Bitwise; let n = 0b01001100u8; assert_eq!(n.count_ones(), 3);
fn leading_zeros(&self) -> Self
Returns the number of leading zeros in the in the binary representation of the number.
Example
use std::num::Bitwise; let n = 0b0101000u16; assert_eq!(n.leading_zeros(), 10);
fn trailing_zeros(&self) -> Self
Returns the number of trailing zeros in the in the binary representation of the number.
Example
use std::num::Bitwise; let n = 0b0101000u16; assert_eq!(n.trailing_zeros(), 3);
Provided Methods
fn count_zeros(&self) -> Self
Returns the number of zeros in the binary representation of the number.
Example
use std::num::Bitwise; let n = 0b01001100u8; assert_eq!(n.count_zeros(), 5);