#include <iostream>
using namespace std;
int Grial(int x)
{
int n = 32;
int count = 0;
while (n--)
{
count|= ((x&0x1) << n);
x = ((unsigned)x >> 1);
}
return count;
}
int main()
{
cout << Grial(1) << endl;
return 0;
}
#include <iostream>
using namespace std;
int Grial(int x)
{
int sum1 = x & 0x55555555;
int sum2 = x & 0xaaaaaaaa;
sum1 <<= 1;
sum2 >>= 1;
return sum1 | sum2;
}
int main()
{
cout << Grial(6) << endl;
return 0;
}
#include <iostream>
using namespace std;
int Grial(int x, int y)
{
if (!y)return x;
int sum = x^y;
int num = ((x&y)<<1);
return Grial(sum,num);
}
int main()
{
cout << Grial(3, 5) << endl;
return 0;
}
#include <iostream>
using namespace std;
bool Grial(int x)
{
return (x&(x - 1)) == 0;
}
int main()
{
cout << Grial(4) << endl;
return 0;
}
#include <iostream>
using namespace std;
int Grial(int x)
{
int count = 0;
while (x)
{
x = x&(x - 1);
count++;
}
return count;
}
int main()
{
cout << Grial(15) << endl;
}
#include <iostream>
using namespace std;
int Grial(int x,int y)
{
return (x&y) + ((x^y) >> 1);
}
int main()
{
cout << Grial(20, 48) << endl;
return 0;
}
#include <iostream>
using namespace std;
int Grial(int x,int y)
{
return x - (x - y) / 2;
}
int main()
{
cout << Grial(3,9) << endl;
return 0;
}