int fits_bits(int x, int n) { int count = sizeof(int) << 3 - n; return ((x << count) >> count) == x; }