Function bitwise::word::reverse_bit_groups
[−]
[src]
pub fn reverse_bit_groups<T: Word, U: UnsignedWord>(x: T,
group_bit_size: U,
no_subwords: U)
-> T
Reverses groups of bits within each subword of x
.
group_bit_size
- The size (in bits) of the groups of bits to be reversed.no_subwords
- The number of subwords inx
.
The word x
is divided into no_subwords
. The bit groups of size
group_bit_size
are reversed within each subword. Bits within a bit group
are not reversed.
The size in bits of a subword is thus x::bit_size() / no_subword
. When
no_suboword == 1
the subword equals the original word. When
group_bit_size == 1
the single bits are reversed within a subword.
Both group_bit_size
and no_subwords
must be a power of 2 and
x::bit_size() / no_subword % group_bit_size == 0
(that is, a subword must
be divisible into bitgroups).
Examples
use bitwise::word::*; let n = 0b0101_1101_1010_0101_u16; // Reverse bits of `n`: assert_eq!(n.reverse_bit_groups(1u32, 1u32), 0b1010_0101_1011_1010u16); // Reverse bit pairs of `n`: assert_eq!(reverse_bit_groups(n, 2u32, 1u32), 0b0101_1010_0111_0101u16); // Reverse bit nibbles (groups of 4 bits) of `n`: assert_eq!(n.reverse_bit_groups(4u32, 1u32), 0b0101_1010_1101_0101u16); // Reverse the bits within each two 8-bit subwords of `n`: assert_eq!(n.reverse_bit_groups(1u32, 2u32), 0b1011_1010_1010_0101u16); // Reverse the bit pairs within each two-8 bit subwords of `n`: assert_eq!(n.reverse_bit_groups(2u32, 2u32), 0b0111_0101_0101_1010u16); // Reverse the bit nibbles within each two 8-bit subwords of `n`: assert_eq!(n.reverse_bit_groups(4u32, 2u32), 0b1101_0101_0101_1010u16); // Reverse bits within each four 4-bit subwords of `n`: assert_eq!(n.reverse_bit_groups(1u32, 4u32), 0b1010_1011_0101_1010u16); // Reverse bit pairs within each four 4-bit subwords of `n`: assert_eq!(n.reverse_bit_groups(2u32, 4u32), 0b0101_0111_1010_0101u16); // Reverse bits within each 8 2-bit subwords of `n`: assert_eq!(n.reverse_bit_groups(1u32, 8u32), 0b1010_1110_0101_1010u16);