pub trait BitHelper {
    fn read_bit(&self, pos: u32) -> bool;
    fn write_bit(&mut self, pos: u32, val: bool) -> &mut Self;
    fn read_bits_in_range(&self, bit_range: &BitRange) -> Self;
    fn write_bits_in_range(
        &mut self,
        bit_range: &BitRange,
        val: Self
    ) -> &mut Self; }
Expand description

Trait containing helper methods for bit operations.

Required Methods

Reads the value of the bit at position pos

Changes the value of the bit at position pos to val

Reads the value stored within the specified range of bits

Example
#[macro_use]
use dbs_arch::cpuid::bit_helper::*;

let val: u32 = 0b000010001000;
let range = BitRange {
    msb_index: 7,
    lsb_index: 3,
};
println!("binary value: {:b}", val.read_bits_in_range(&range));

The code above will print:

binary value: 10001

Stores a value within the specified range of bits

Example
#[macro_use]
use dbs_arch::cpuid::bit_helper::*;

let mut val: u32 = 0;
let range = BitRange {
    msb_index: 7,
    lsb_index: 3,
};
val.write_bits_in_range(&range, 0b10001 as u32);
println!("binary value: {:b}", val);

The code above will print:

binary value: 10001000

Implementations on Foreign Types

Implementors