chsvlib
chsv helper source code

◆ memneg_BE_copy()

bool Chusov::Memory::memneg_BE_copy ( void *restrict  pDest,
const void *restrict  pSrc,
std::size_t  cbData 
)
noexcept

Calculates an additive inversion of an arbitrary-precision integer given by a vector of bytes in the Big-Endian order and writes it to a separate buffer returning the value of the highest bit of the result.

Parameters
[out]pDestA pointer to the destination buffer which receives a two's complement of the input integer with respect to 2CHAR_BIT cbData. The capacity of the buffer must be at least cbData bytes.
[in]pSrcA pointer to a vector of cbData bytes given in the Big-Endian order to specify the input integer. The buffer must not overlap with the destination buffer.
cbDataSize of the input integer and a capacity of the output buffer specified in bytes.
Returns
A value of the highest bit of the result.

The function considers the input vector to specify the integer in the Big-Endian byte order. That is, given that \(V_X = \{x_0, \dots, x_n\}\) is the input vector pointed to by pSrc, such that \(x_0\) is the first byte in memory of the vector, \(x_n\) is the last byte and n = cbData - 1, the input value for the operation is \(X = \sum_{i=0}^{n}x_{n-i}i\cdot b^i\), where b = 2CHAR_BIT is a number of values that can be represented with one byte. To negate Little-Endian integers use memneg_LE_copy.

The buffers pointed to by pDest and pSrc may not overlap. To negate an integral value in place use memneg_BE_inplace. The memneg_BE function, which also allows buffers of differing sizes, can negate an integer in place or with copying of the result to a separate buffer.

See also
memneg_LE_copy;
memneg_BE_inplace;
memneg_BE;
memincr_BE;
memdecr_BE;
memadd_BE;
memsub_BE.