I am trying to XOR tow 128 bit bitsets.
#include<iostream>
#include<bitset>
int main()
{
std::bitset<128> testing;
testing = std::bitset<128>(0x544F4E20776E69546F656E772020656F) ^
std::bitset<128>(0x5473206768204B20616D754674796E75);
std::cout<<testing;
}
The output I get is
The first 64 bits are 0 and the last 64 bits are XOR. I also get a compiler warning
warning: integer constant is too large for its type
Is there some way to XOR 128 bit bitsets or do I need to create an ugly hack?
Your problem is not the XOR, but initializing the bitsets from a constant. As the warning says, there is a limit to the size that integer constants can have, and std::bitset
constructor takes an unsigned long long
which is usually 64 bits long.
You can initialize the bitsets from a binary string instead:
std::bitset<128>("100101010....")
Or combine it from two 64-bit bitsets:
std::bitset<128> value = (std::bitset<128>(0x1234567890123456) << 64) |
std::bitset<128>(0x1234567890123456);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With