Crates.io | bigwise |
lib.rs | bigwise |
version | 0.4.0 |
source | src |
created_at | 2015-06-05 23:37:00.415055 |
updated_at | 2015-12-11 23:57:49.028558 |
description | Bitwise operations on fixed-size, arbitrary big buffer of bytes. |
homepage | |
repository | https://bitbucket.org/olivren/bigwise |
max_upload_size | |
id | 2311 |
size | 266,880 |
This is a Rust library that provides bitwise operations on fixed-size, arbitrary big buffer of bytes.
The primitive types u8
, u16
, u32
and u64
are very useful types,
when one needs to perform boolean algebra on many bits at once (bitwise
operations).
This library complements these primitive types, with subsequent power-of-two
sizes: Bw128
, Bw256
, etc. These types are all Copy
(that is, they can
be trivially copied as raw memory), and their size is really the size given
by their names (Bw256
takes 256 bits). You may be quickly limited by
Rust's default stack size if you store these types directly on the stack.
Don't forget to box your values if you want them to live on the heap!
If the types provided are not enough, you can easily define your own by
creating an alias to a BwPair<X>
. Only power-of-two sizes are supported.
use bigwise::{Bigwise, Bw128};
let b1 = Bw128::from_bytes(&[0b00110110, 0b10001101]);
let b2 = b1 << 90;
let b3 = Bw128::full() >> 60;
let b4 = b1.rotate_right(5);
let b5 = (b2 & !b3) | b4;
print!("{:?}", b5);