twiddle

A small library for bit-twiddling.

You can use it as a dependency by adding it to your Cargo.toml file.

toml [dependencies] twiddle = "*"

Documentation

Example

```rust extern crate twiddle;

use twiddle::Twiddle;

struct UnpackedF32 { negative: bool, exponent: i16, fraction: u32, }

impl From for UnpackedF32 { fn from(f: f32) -> UnpackedF32 { let b = unsafe { std::mem::transmute::(f) }; UnpackedF32 { negative: b.bit(31), exponent: (b.bits(30..23) as i16) - 127, fraction: b.bits(22..0) } } }

fn main() { for f in (-5..6) { let u = UnpackedF32::from(f as f32); println!("{:+} = {}1.{:023b} * 2^{}", f, match u.negative { false => "+", true => "-" }, u.fraction, u.exponent ); } } ```

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.