reversing
Reverses the order of elements in a value by extracting and reassembling them
This generic function reverses the ordering of elements within a value by repeatedly dividing by a step size and building the result in reverse order. It’s commonly used for reversing bits or bytes within numeric types.
The step parameter MUST be a power of 2 (e.g., 2, 256, 65536).
Using a non-power-of-2 step will produce incorrect results and data corruption.
Valid steps: 2 (bits), 256 (bytes), 65536 (u16 words), etc.
Arguments
word- The value to reversesize- The number of elements to reversestep- The step size for each element (MUST be a power of 2: 2, 256, 65536, etc.)
Returns
(T, T)- A tuple containing (reversed_value, remaining_value)
Panics
- If
stepis not a power of 2 (runtime check performed)
Fully qualified path: alexandria_bytes::reversible::reversing
pub fn reversing<
T,
+Copy<T>,
+Zero<T>,
+TryInto<T, NonZero<T>>,
+Into<T, u128>,
+TryInto<u128, T>,
+DivRem<T>,
+Drop<T>,
+MulAssign<T, T>,
+Rem<T>,
+AddAssign<T, T>,
>(
word: T, size: u32, step: T,
) -> (T, T)