The *EqBits
functions (andEqBits
, minusEqBits
, orEqBits
, and xorEqBits
), have the following signature: void function(uint64_t *dstValue,
int dstIndex,
uint64_t srcValue,
int numBits);
First, we demonstrate the andEqBits
function: +--------------------------------------------------------------------------+
| 'bdlb::BitStringImpUtil::andEqBits(&dstValue, 8, 0, 8)' in binary: |
| |
| 'dstValue' before in binary: 0..00000000000000000011001100110011 |
| 'srcValue == 0' in binary: 0..00000000000000000000000000000000 |
| 'srcValue', 0x00, at index 8: 00000000 |
| 'dstValue' after in binary: 0..00000000000000000000000000110011 |
+--------------------------------------------------------------------------+
uint64_t dstValue;
dstValue = 0x3333;
bdlb::BitStringImpUtil::andEqBits(&dstValue, 8, 0, 8);
assert(static_cast<uint64_t>(0x33) == dstValue);
Then, we apply andEqBits
with all bits set in the relevant part of 'srcValue, which has no effect: +--------------------------------------------------------------------------+
| 'bdlb::BitStringImpUtil::andEqBits(&dstValue, 8, 0, 8)' in binary: |
| |
| 'dstValue' before in binary: 0..00000000000000000011001100110011 |
| 'srcValue == 0xffff' in binary: 0..00000000000000001111111111111111 |
| 'srcValue', 0xff, at index 8: 11111111 |
| 'dstValue' after in binary: 0..00000000000000000011001100110011 |
+--------------------------------------------------------------------------+
dstValue = 0x3333;
bdlb::BitStringImpUtil::andEqBits(&dstValue, 8, 0xffff, 8);
assert(static_cast<uint64_t>(0x3333) == dstValue);
Next, we demonstrate orEqBits
, which takes low-order bits of a srcValue
and bitwise ORs them with dstValue
: +--------------------------------------------------------------------------+
| 'bdlb::BitStringImpUtil::orEqBits(&dstValue, 16, 0xffff, 8)' in binary: |
| |
| 'dstValue' before in binary: 0..00110011001100110011001100110011 |
| 'srcValue == 0xffff' in binary: 0..00000000000000001111111111111111 |
| 'srcValue', 0xff, at index 16: 11111111 |
| 'dstValue' after in binary: 0..00110011111111110011001100110011 |
+--------------------------------------------------------------------------+
dstValue = 0x33333333;
bdlb::BitStringImpUtil::orEqBits(&dstValue, 16, 0xffff, 8);
assert(static_cast<uint64_t>(0x33ff3333) == dstValue);
Then, we demonstrate applying the same operation where *dstValue
is initially 0: +--------------------------------------------------------------------------+
| 'bdlb::BitStringImpUtil::orEqBits(&dstValue, 16, 0xffff, 8)' in binary: |
| |
| 'dstValue' before in binary: 0..00000000000000000000000000000000 |
| 'srcValue == 0xffff' in binary: 0..00000000000000001111111111111111 |
| 'srcValue', 0xff, at index 16: 11111111 |
| 'dstValue' after in binary: 0..00000000111111110000000000000000 |
+--------------------------------------------------------------------------+
dstValue = 0;
bdlb::BitStringImpUtil::orEqBits(&dstValue, 16, 0xffff, 8);
assert(static_cast<uint64_t>(0x00ff0000) == dstValue);
Now, we apply another function, xorEqBits
, that takes the low-order bits of srcValue
and bitwise XORs them with dstValue
: +--------------------------------------------------------------------------+
| 'bdlb::BitStringImpUtil::xorEqBits(&dstValue, 16, 0xffff, 8)' in binary: |
| |
| 'dstValue' before in binary: 0..01110111011101110111011101110111 |
| 'srcValue', 0xff, at index 16: 11111111 |
| 'dstValue' after in binary: 0..01110111100010000111011101110111 |
----------------------------------------------------------------------------
dstValue = 0x77777777;
bdlb::BitStringImpUtil::xorEqBits(&dstValue, 16, 0xffff, 8);
assert(static_cast<uint64_t>(0x77887777) == dstValue);
Finally, we apply the same function with a different value of srcValue
and observe the result: +--------------------------------------------------------------------------+
| 'bdlb::BitStringImpUtil::xorEqBits(&dstValue, 16, 0x5555, 8)' in binary: |
| |
| 'dstValue' before in binary: 0..01110111011101110111011101110111 |
| 'srcValue', 0x55, at index 16: 01010101 |
| 'dstValue' after in binary: 0..01110111001000100111011101110111 |
+--------------------------------------------------------------------------+
dstValue = 0x77777777;
bdlb::BitStringImpUtil::xorEqBits(&dstValue, 16, 0x5555, 8);
assert(static_cast<uint64_t>(0x77227777) == dstValue);