chsvlib
chsv helper source code

◆ memlsh_BE()

void Chusov::Memory::memlsh_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 left.

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 left 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 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_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 left by \(2B\), results in the value \(\overline{b_2 b_3 b_4 0 0} = b_2\cdot B^4 + b_3\cdot B^3 + b_4 B^2 + 0 \cdot B^1 + 0 \cdot 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 left is used.

Unlike memlsh_BE_copy and memlsh_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
memlsh_BE_copy;
memlsh_BE_inplace;
memrsh_BE;
memlsh_LE.
Examples
chsvmem\memory_shifts.c.