chsvlib
chsv helper source code

◆ memrsh_BE()

void Chusov::Memory::memrsh_BE ( 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 Big-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 specified as a byte vector in the Big-Endian 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 more significant that \(b_j\). Therefore, the operation shifts the value towards the end 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_0 B^4 + b_1 B^3 + b_2 B^2 + b_3 B^1 + b_4 B^0 = \overline{b_0 b_1 b_2 b_3 b_4}\), when shifted to the right by \(2B\), results in the value \(\overline{0 0 b_0 b_1 b_2} = 0 \cdot B^4 + 0 \cdot B^3 + b_0 B^2 + b_1 B^1 + b_2 B^0\) which is represented by the vector \(\left\{0, 0, b_0, b_1, b_2\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_BE_copy and memrsh_BE_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_BE_copy;
memrsh_BE_inplace;
memlsh_BE;
memrsh_LE.
Examples
chsvmem\memory_shifts.c.