Struct Gray
pub struct Gray<#uint N> {
inner: uint<N>,
}Expand
A number encoded into Gray code.
Gray code is notable for making adjacent values differ in a single bit. This property makes it useful in hardware for things like counters that cross clock domain boundaries.
Implementations
impl<#uint N> Gray<N>
pub fn as_bits(self) -> [bool; N]
Casts a Gray-coded number to an array of bool by reinterpreting its bits.
Examples
assert std::num::Gray(0b00).as_bits() == [false, false];
assert std::num::Gray(0b01).as_bits() == [ true, false];
assert std::num::Gray(0b11).as_bits() == [ true, true];
assert std::num::Gray(0b10).as_bits() == [false, true];fn to_uint(self) -> uint<N>
Decodes a Gray-code number back into binary.
Examples
assert std::num::Gray(0b00).to_uint() == 0u2;
assert std::num::Gray(0b01).to_uint() == 1u2;
assert std::num::Gray(0b11).to_uint() == 2u2;
assert std::num::Gray(0b10).to_uint() == 3u2;
assert 20u8.to_gray().to_uint() == 20u8;