intbitCount(int x) { int ans = 0; int fence = (0x11 << 24) | (0x11 << 16) | (0x11 << 8) | (0x11); int tmp = x & fence; x = x >> 1; tmp = tmp + (x & fence); x = x >> 1; tmp = tmp + (x & fence); x = x >> 1; tmp = tmp + (x & fence); // get count of per 4 bits // do and operation per 4 bits, add the result to ans ans = tmp & 0x0f; tmp = tmp >> 4; ans = ans + (tmp & 0x0f); tmp = tmp >> 4; ans = ans + (tmp & 0x0f); tmp = tmp >> 4; ans = ans + (tmp & 0x0f); tmp = tmp >> 4; ans = ans + (tmp & 0x0f); tmp = tmp >> 4; ans = ans + (tmp & 0x0f); tmp = tmp >> 4; ans = ans + (tmp & 0x0f); tmp = tmp >> 4; ans = ans + (tmp & 0x0f);