#bits #set-bit #bit-manipulation #iterator #flags #bit-set #bit

no-std bit-iter

Iterate forward or backwards over the positions of set bits in a word

6 releases (stable)

1.2.0 Aug 24, 2023
1.1.1 May 18, 2022
1.1.0 Nov 12, 2021
0.1.6 Sep 29, 2021
0.1.4 Jun 23, 2021

#231 in Algorithms

Download history 1084/week @ 2024-01-04 1195/week @ 2024-01-11 989/week @ 2024-01-18 2034/week @ 2024-01-25 3167/week @ 2024-02-01 1935/week @ 2024-02-08 2170/week @ 2024-02-15 2523/week @ 2024-02-22 1461/week @ 2024-02-29 1417/week @ 2024-03-07 1199/week @ 2024-03-14 1449/week @ 2024-03-21 1213/week @ 2024-03-28 1407/week @ 2024-04-04 1587/week @ 2024-04-11 1288/week @ 2024-04-18

5,718 downloads per month
Used in 3 crates

MIT license

13KB
258 lines

bit-iter

Test results Crates.io Documentation

Iterate forwards or backwards over the positions of bits set in a word.

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

fn main() {
    use bit_iter::*;

    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.

Minimum supported Rust version (MSRV) policy

bit-iter's current minimum supported Rust version (MSRV) is 1.53.0.

bit-iter is guaranteed to compile with that version. It might also compile with older versions, but that could change in a future patch release.

If the MSRV of bit-iter changes, that will be done in a minor version release (e.g. 1.2.x -> 1.3.0).

No runtime deps