Bitit
A library for bitwise iteration over Rust integers.
Provides simple and efficient iterators for binary integer types.
Examples
use BitIter;
let x = 0b10101100u8;
// Iterating each bit:
let mut bits = x.bits;
assert_eq!;
assert_eq!;
assert_eq!;
// Or just the ones:
let mut ones = x.ones;
assert_eq!;
assert_eq!;
assert_eq!;
// Or the zeros, even with indices:
let mut zero_indices = x.zero_indices;
assert_eq!;
assert_eq!;
assert_eq!;
// Works with floats too like this:
let f = -5.0f64;
let mut ieee_bits = f.to_bits.bits_rev;
// Now we can see its bits, such as the sign bit:
if ieee_bits.next == Some else
cargo run -q
-5 is negative.
Features
Bitit provides the following iterators with the BitIter trait:
- Iterating ones from least to most significant with
BitIter::ones - Iterating zeros from least to most significant with
BitIter::zeros - Iterating the bitwise indices of all ones with
BitIter::one_indices - Iterating the bitwise indices of all zeros with
BitIter::zero_indices - Iterating all bits as booleans from least to most significant with
BitIter::bits - Iterating all bits as booleans from most to least significant with
BitIter::bits_rev - The ability to reverse all iterators (except
BitIter::bitswhich hasBitIter::bits_rev) withIterator::rev
The BitIter trait is implemented for all signed and unsigned primitive integers i8, u8, i16, etc. as well as usize and isize.