chsvlib
chsv helper source code

◆ memsub_BE_copy()

bool Chusov::Memory::memsub_BE_copy ( void *restrict  pResult,
const void *restrict  pX,
const void *restrict  pY,
std::size_t  cb 
)
noexcept

Computes a difference between two distinct arbitrary-precision integers given in the Big-Endian byte order, writes the difference to a separate buffer and returns the resulting borrow bit.

Parameters
[out]pResultA pointer to a buffer which receives the difference. The capacity of the buffer must be at least cb bytes.
[in]pXA pointer to an arbitrary-precision integral subtrahend represented as a vector of bytes. The size of the integer is cb bytes.
[in]pYA pointer to the minuend of cb bytes in size.
cbByte size of the operands and the capacity of the output buffer.
Returns
true if a borrow has taken place and false otherwise.

The subtraction is carried out modulo bcb, where b = 2CHAR_BIT is a number of values that a byte can represent.

All of the integers are specified with vectors in the Big-Endian byte order. That is, if n = cb - 1, and the first and the second integers are respectively specified with vectors \(V_X = \{x_0,\dots, x_n\}\) and \(V_Y = \{y_0,\dots, y_n\}\), where \(x_0\) and \(y_0\) are the first bytes of the vectors, then the respective integers are defined as \(X=\sum_{i=0}^{n}x_i\cdot b^i\) and \(Y=\sum_{i=0}^{n}y_i\cdot b^i\). The difference \(X - Y\) is also written to pResult in the Little-Endian byte order.

To subtract numbers given in the Little-Endian byte order use memsub_LE_copy.

None of the buffers may overlap. To perform a subtraction in place use memsub_BE_inplace, memnegsub_BE_inplace or memsub_BE.

See also
memsub_LE_copy;
memsub_BE_inplace;
memnegsub_BE_inplace;
memsub_BE;
memdecr_BE;
memneg_BE;
memadd_BE;
memmul_BE;
memfmsub_BE;
memdiv_BE.