intlogicalNeg(int x) { int x1 = (x >> 16) | x; int x2 = (x1 >> 8) | x1; int x3 = (x2 >> 4) | x2; int x4 = (x3 >> 2) | x3; int x5 = (x4 >> 1) | x4; return (~x5 & 1); }
inthowManyBits(int x) { int ans = 0;
x = (x >> 1) ^ x;
ans = ans + ((!!(x >> 15)) << 4);
ans = ans + ((!!(x >> (ans + 7))) << 3); ans = ans + ((!!(x >> (ans + 3))) << 2); ans = ans + ((!!(x >> (ans + 1))) << 1); ans = ans + (!!(x >> ans)); return ans + 1; }