Quote:
how to compute the XOR of two binary strings and find the number of distinct values of this XOR which can be obtained, modulo 1,000,000,007 ( 109+7
Without correct context, this means nothing.
Your code is not related to strings!
This code :
int performXOR(int x, int y)
{
int res = 0;
for (int i = 31; i >= 0; i--)
{
bool b1 = x & (1 << i);
bool b2 = y & (1 << i);
bool xoredBit = (b1 & b2) ? 0 : (b1 | b2);
res <<= 1;
res |= xoredBit;
}
return res;
}
can ve simplified to :
int performXOR(int x, int y)
{
return x ^ y;
}
Bitwise Operators in C/C++ - GeeksforGeeks[
^]