Silly question but, does setting bits on a cpp_int
from the boost
library work the same as normal numbers?
For instrance, I tried to set some bits on a number like so:
vector<bool> bits; //contains 000000000000011010001100101110110011011001101111
cpp_int M = 0;
int k = 48;
for(bool b : bits) M ^= (-b ^ M) & (1UL << k--);
bits.clear();
bits = toBinary(M); //contains 11001011101100110110011011111
The toBinary(cpp_int&x)
method I have gets bits from the number in the simplest way:
vector<int> toBinary(cpp_int&x) {
vector<int> bin;
while (x > 0) {
bin.push_back(int(x % 2));
x /= 2;
}
reverse(bin.begin(), bin.end());
return bin;
}
I can understand losing the 14 zeros in the beginning, what I don't understand is why do lose not 14 but 20 whole bits. I am fairly new to the boost
library, so it's most likely a rookie mistake.