chsvlib
chsv helper source code

◆ memrsh_BE_copy()

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

Bit-shifts a long integer specified by a vector of bytes in the Big-Endian byte order to the right and copies the result into a separate output buffer.

Parameters
[out]pResultThe output buffer receiving the result of the shift. The buffer may not overlap with the input buffer given by pValue.
[in]pValueAn input buffer containing bytes of the long integer.
cbValueA byte size of the data in pValue and the capacity of the output buffer pResult.
nShiftA value by which the input integer is bit-shifted to the right, that is towards the end 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 result would be a copy of the input. If the value is greater or equal to cbValue * CHAR_BIT, the resulting integer will be zero, and the corresponding buffer pResult is zeroed out by the function.

The function performs a bit-shift of an integer specified with 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.

The buffers pResult and pValue may not overlap. To perform the action within overlapping input and output buffers use the generic memrsh_BE function. To shift inplace one can also use the memrsh_BE_inplace function.

See also
memrsh_BE_inplace;
memrsh_BE;
memlsh_BE_copy;
memlsh_BE_inplace.