2.62. Solutions are not unique. int int_shifts_are_logical() { int a = -1; // Sign bit set to 1. return (a >> 1) > 0; // Keep sign bit or not? /* or return (a >> (8*sizeof(int)-1)) == 1; This shifts the sign bit. */ } 2.64. int any_even_one(unsigned int x) { return (x & 0x55555555) != 0; } Counting bits. int count_bits(int a) { int c = 0; int i; for(i = 0; i < 32; ++i) { if (a & (1 << i)) c++; /* or: c += (a & 1); a >>= 1; */ } return c; } This is a straight-forward solution that is not very efficient. We'll see later something better. There are other ways. This one is interesting: int count_bits(int a) { static const int counts[16] = { 0 /* 0 */, 1 /* 1 */, 1 /* 2 */, 2 /* 3 */, 1 /* 4 */, 2 /* 5 */, 2 /* 6 */, 3 /* 7 */, 1 /* 8 */, 2 /* 9 */, 2 /* 10*/, 3 /* 11*/, 2 /* 12*/, 3 /* 13*/, 3 /* 14*/, 4 /* 15*/ }; int c = 0; int i; for(i = 0; i < 32; i += 4) { c += counts[(a >> i) & 0xf]; } return c; } 2.65. Not respecting the 12 instructions limit is easy, e.g., return (count_bits(x) & 1) == 0; will do. To respect the limit we can use xor with bits on the integers. int even_ones(unsigned int x) { x ^= (x >> 16); x ^= (x >> 8); x ^= (x >> 4); x ^= (x >> 2); x ^= (x >> 1); return (x & 1) == 0; } 2.70. Several solutions to that one. int fits_bits(int x, int n) { int count = 8*sizeof(int) - n; return ((x << count) >> count) == x; } 2.74. See 2.30. 2.83. int float_ge(float x, float y) { unsigned ux = f2u(x); unsigned uy = f2u(y); unsigned sx = ux >> 31; unsigned sy = uy >> 31; return (ux<<1 == 0 && uy<<1 == 0) || /* Both are zero */ (!sx && sy) || /* x >= 0, y < 0 */ (!sx && !sy && ux >= uy) || /* x >= 0, y >= 0 */ (sx && sy && ux <= uy); /* x < 0, y < 0 */ }