Crates.io | bit |
lib.rs | bit |
version | 0.1.1 |
source | src |
created_at | 2017-04-11 18:22:40.471034 |
updated_at | 2017-04-12 10:31:36.240428 |
description | A library which provides helpers to manipulate bits and bit ranges. |
homepage | |
repository | https://github.com/jmi2k/bit-rs |
max_upload_size | |
id | 10317 |
size | 18,517 |
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:
bitflags
-like functionality.Add to your Cargo.toml
:
[dependencies]
bit = "0.1"
And add to your code:
extern crate bit;
use bit::BitIndex;
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);
}