Trait bit_range::BitRange [] [src]

pub trait BitRange {
    fn get_bit_range(&self, range: Range<u32>) -> u32;
    fn get_bit(&self, bit: u32) -> bool;
}

A trait for getting subsections of bits from containers of bytes.

Required Methods

fn get_bit_range(&self, range: Range<u32>) -> u32

Takes a range and converts the bits in that range into a u32.

Examples

use bit_range::BitRange;
let bytes = [0b0010_0111, 0b0110_0110];
assert_eq!(bytes.get_bit_range(5..12), 0b1110110);

fn get_bit(&self, bit: u32) -> bool

Takes an index and gets the bit at that index.

use bit_range::BitRange;
let bytes = vec![0b0010_0111, 0b110_0110];
assert_eq!(bytes.get_bit(2), true);
assert_eq!(bytes.get_bit(3), false);

Implementors