#bit-manipulation #bits #boolean #shift #bool #bit

bigwise

Bitwise operations on fixed-size, arbitrary big buffer of bytes

4 releases (breaking)

Uses old Rust 2015

0.4.0 Aug 11, 2015
0.3.0 Jun 15, 2015
0.2.0 Jun 7, 2015
0.1.0 Jun 5, 2015

#15 in #shift

MIT license

96KB
886 lines

Bigwise

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.

Examples

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);

Dependencies

~315–540KB