#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

#220 in No standard library

Download history 1920/week @ 2024-07-22 854/week @ 2024-07-29 1089/week @ 2024-08-05 1462/week @ 2024-08-12 1522/week @ 2024-08-19 1263/week @ 2024-08-26 1168/week @ 2024-09-02 1047/week @ 2024-09-09 450/week @ 2024-09-16 1033/week @ 2024-09-23 472/week @ 2024-09-30 720/week @ 2024-10-07 1271/week @ 2024-10-14 1121/week @ 2024-10-21 1248/week @ 2024-10-28 1556/week @ 2024-11-04

5,214 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