Crate bit_iter[−][src]
Expand description
Iterate over the bits set in a word.
A BitIter
may be constructed from any integral value.
A BitIter
may be constructed from any integral value, and returns the positions of the 1
bits in ascending order.
BitIter
implements DoubleEndedIterator
, so you can iterate over the positions of the set
bits in descending order too.
Example
let x : u32 = 0x10001; for b in BitIter::from(x) { println!("Bit {} is set.", b); } println!("In reverse order:"); for b in BitIter::from(x).rev() { println!("Bit {} is set.", b); }
Output:
Bit 0 is set. Bit 16 is set. In reverse order: Bit 16 is set. Bit 0 is set.
Structs
An iterator which returns the positions of the set bits in a word, in ascending order.