#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

#212 in No standard library

Download history 1594/week @ 2024-11-16 1357/week @ 2024-11-23 1446/week @ 2024-11-30 1508/week @ 2024-12-07 1340/week @ 2024-12-14 669/week @ 2024-12-21 463/week @ 2024-12-28 1293/week @ 2025-01-04 1592/week @ 2025-01-11 1159/week @ 2025-01-18 264/week @ 2025-01-25 1303/week @ 2025-02-01 1796/week @ 2025-02-08 1385/week @ 2025-02-15 1296/week @ 2025-02-22 1394/week @ 2025-03-01

6,068 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