#bit-range #helper #no-std

no-std bit

A library which provides helpers to manipulate bits and bit ranges

2 releases

Uses old Rust 2015

0.1.1 Apr 12, 2017
0.1.0 Apr 11, 2017

#3 in #bit-range

Download history 970/week @ 2025-10-25 1473/week @ 2025-11-01 1093/week @ 2025-11-08 1558/week @ 2025-11-15 1674/week @ 2025-11-22 1343/week @ 2025-11-29 1633/week @ 2025-12-06 1792/week @ 2025-12-13 1116/week @ 2025-12-20 915/week @ 2025-12-27 1303/week @ 2026-01-03 971/week @ 2026-01-10 1322/week @ 2026-01-17 2562/week @ 2026-01-24 1871/week @ 2026-01-31 1793/week @ 2026-02-07

7,856 downloads per month
Used in 48 crates (10 directly)

MIT/Apache

7KB
104 lines

This crate adds simple bit-manipulation helpers in a convenient trait. Also, it implements them for the unsigned primitive types.


Bit

crates.io version badge

bit is a library which provides some useful helpers for dealing with bits and bit ranges. For now it's just a rewrite of rust-bit-field crate, but more features are planned. Some of them could be:

  • Support for arrays and slices.
  • bitflags-like functionality.

Usage

Add to your Cargo.toml:

[dependencies]
bit = "0.1"

And add to your code:

extern crate bit;
use bit::BitIndex;

Example

extern crate bit;
use bit::BitIndex;

fn main() {
    let mut value = 0b11010110u8;

    // 8
    println!("{}", u8::bit_length());

    // true
    println!("{}", value.bit(1));

    // 0b10
    println!("{:#b}", value.bit_range(0..2));

    value
        .set_bit(3, true)
        .set_bit(2, false)
        .set_bit_range(5..8, 0b001);

    // 0b111010
    println!("{:#b}", value);
}

No runtime deps