#bit #bits #int

no-std intbits

Easy access to individual bits of integers

2 unstable releases

0.2.0 Sep 29, 2020
0.1.2 Feb 17, 2020
0.1.1 Sep 27, 2019
0.1.0 Sep 27, 2019

#183 in No standard library

Download history 2991/week @ 2024-04-23 1611/week @ 2024-04-30 2132/week @ 2024-05-07 2133/week @ 2024-05-14 2257/week @ 2024-05-21 2566/week @ 2024-05-28 1416/week @ 2024-06-04 2417/week @ 2024-06-11 2658/week @ 2024-06-18 2451/week @ 2024-06-25 2783/week @ 2024-07-02 2940/week @ 2024-07-09 3618/week @ 2024-07-16 1427/week @ 2024-07-23 997/week @ 2024-07-30 1150/week @ 2024-08-06

7,679 downloads per month
Used in 17 crates (2 directly)

BSD-2-Clause

14KB
330 lines

intbits

Easy access to individual bits of integers

use intbits::Bits;

assert_eq!(2.bit(0), false);
assert_eq!(2.bit(1), true);
assert_eq!(2.bit(2), false);

assert_eq!(0b1011u32.bits(0..2), 0b11);
assert_eq!(0b1011u32.bits(2..4), 0b10);

assert_eq!(0xFFu8.with_bit(3, false), 0xF7);
assert_eq!(0xFFu8.with_bits(4..8, 3), 0x3F);

See the documentation.


lib.rs:

This crates provides two functions for accessing the individual bits of integers:

It also provides similar functions for changing specific bits of integers:

These variants return a new integer, instead of modifying it:

Example

use intbits::Bits;

assert_eq!(2.bit(0), false);
assert_eq!(2.bit(1), true);
assert_eq!(2.bit(2), false);

assert_eq!(0b1011u32.bits(0..2), 0b11);
assert_eq!(0b1011u32.bits(2..4), 0b10);

assert_eq!(0xFFu8.with_bit(3, false), 0xF7);
assert_eq!(0xFFu8.with_bits(4..8, 3), 0x3F);

No runtime deps