|
noexcept |
The generic form of bitwise NOT of an arbitrary-precision value specified in the Little-Endian byte order.
[out] | pDest | A pointer to the output buffer receiving the one's complement of the input modulo bcbDest , where b = 2CHAR_BIT is a number of values that can be represented using one byte. |
cbDest | The capacity of the destination buffer pDest , in bytes, and the byte length of the integral result. | |
[in] | pSrc | A pointer to the input integral operand. |
cbSrc | A byte length of the operand pointed to by pSrc . |
The function computes bitwise NOT of an arbitrary-precision integer and writes the result into the buffer pDest
, of a custom size cbDest
, that can overlap with the input buffer. That is, there are no restrictions on respective values of the sizes or respective positions of the buffers in memory.
Let \(n = \textrm{cbSrc}\), \(m = \textrm{cbDest}\) and \(N = \min (n, m)\). Let also \(x\) be the value specified by the input buffer pSrc
, i.e. \(x=\sum_{i=0}^{n - 1}x_i\cdot b^i\). Then the function produces the result \(R = \left(\sum_{i=0}^{n-1}\bar{x_i}\cdot b^i\right)\bmod b^m = \sum_{i=0}^{N-1}\bar{x_i}\cdot b^i + \sum_{i=N}^{m - 1}\bar{0}\cdot b^i\), where \(\bar{x}\) is one's complement (bitwise NOT) of byte \(x\).
That is, if cbSrc
is greater than cbDest
, then the result of bit complementation is truncated to cbDest
lowest byte and then written to pDest
. Otherwise, if cbSrc
is less than cbDest
, then the remaining cbDest - cbSrc
high-order bytes of the destination buffer have their all bits set.
The function considers the specified parameters be in the Little-Endian format. That is, using the notation above, the first byte of pSrc
specifies \(x_0\), and the last one specifies \(x_{n - 1}\). Likewise, the result is written in the Little-Endian format, therefore the first byte of the destination buffer receives the value of \(\bar{x_0}\), the second byte receives \(\bar{x_1}\) and so on.
To perform a computation of values in the Big-Endian order, use the memnot_BE function.
Compared to memnot_copy and memnot_inplace, the function also performs necessary calculations to match the process with the possibly overlapping buffers of differing sizes. If the operation of the function is known to be conducted with non-overlapping buffers of equal sizes, the preferable faster function for that is memnot_copy. If the operation is done in place with otherwise non-overlapping buffers, the faster alternative is memnot_inplace.