chsvlib
chsv helper source code

◆ memrsh_LE()

void Chusov::Memory::memrsh_LE ( void *  pResult,
std::size_t  cbResult,
const void *  pValue,
std::size_t  cbValue,
std::size_t  nShift 
)
noexcept

Performs a linear bit shift of data representing an unsigned arbitrary precision integer in the Little-Endian format to the right.

Parameters
[out]pResultis a pointer to an output buffer of size cbResult bytes. The buffer receives the shifted result modulo 2cbResult. The buffers pResult and pValue may overlap.
cbResultCapacity of the output buffer pointed to by pResult, in bytes. The result of the operation is computed modulo 2cbResult.
[in]pValueis a pointer to the input data to shift.
cbValueis a byte size of the input data pointed to by pValue.
nShiftspecifies a number of bits by which to shift the input data.

The function performs a right bit-shift of an unsigned integer (i.e. with zero-propagation) specified as a vector of bytes in the Little-Endian byte order. That is, given that \(b_i\) and \(b_j\) are bytes in the vector pValue, such that \(i,j\in\mathbb{N}_0\land i < j\), byte \(b_i\) is less significant that \(b_j\). Therefore, the operation shifts the value towards the beginning of the buffer pValue.

For instance, given that \(B\) is a size of a byte in bits, a vector \(\left\{b_0, b_1, b_2, b_3, b_4\right\}\) representing a number \(b_4 B^4 + b_3 B^3 + b_2 B^2 + b_1 B^1 + b_0 B^0 = \overline{b_4 b_3 b_2 b_1 b_0}\), when shifted to the right by \(2B\), results in the value \(\overline{0 0 b_4 b_3 b_2} = 0\cdot B^4 + 0\cdot B^3 + b_4 B^2 + b_3 B^1 + b_2 B^0\) which is represented by the vector \(\left\{b_2, b_3, b_4, 0, 0\right\}\). The bit order within a byte is not taken into account, that is platform-defined bit shift to the right is used.

Unlike memrsh_LE_copy and memrsh_LE_inplace, the function allows shifting of data in overlapping buffers pointed to by pResult and pValue of possibly differing sizes. The result of the shift is calculated modulo 2cbResult, that is the actual result, depending on the value of cbResult, is either zero-extended or truncated (preserving low-order bytes) to fit the capacity.

See also
memrsh_LE_copy;
memrsh_LE_inplace;
memlsh_LE;
memrsh_BE.
Examples
chsvmem\memory_shifts.c.