chsvlib
chsv helper source code

◆ memlsh_BE_inplace()

void Chusov::Memory::memlsh_BE_inplace ( void *  pValue,
std::size_t  cbValue,
std::size_t  nShift 
)
noexcept

Performs an in-place bit-shift of a long integer specified by a vector of bytes in the Big-Endian order to the left.

Parameters
[in,out]pValueA pointer to a bit-shifted arbitrary precision integer, of the byte size cbValue and Big-Endian byte order.
cbValueA byte size of the data pointed to by pValue.
nShiftA value by which the input integer is bit-shifted to the left, that is towards the beginning of the buffer pValue. The value can accept every element of the domain specified by its type size_t. If the value is 0, the integer pValue is left unchanged. If the value is greater than or equal to cbValue * CHAR_BIT, the resulting integer will be zero, and the corresponding buffer pValue is zeroed out by the function.

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.

The memlsh_BE_copy function can be used in order to write the result of bit-shifting to a separate buffer leaving the original integer unmodified. Use the generic version, memlsh_BE, of the function to perform the shift in possibly overlapping input and output buffers of possibly differing sizes.

See also
memlsh_BE_copy;
memlsh_BE;
memrsh_BE_inplace;
memrsh_BE_copy.
Examples
chsvmem\memory_shifts.c.