highest_set_bit(int foo) { int x = sizeof(foo) * 8 - 1; if (!foo) return 0; for (; x > 0; x--) { if (foo & (1 << x)) break; } return (1 << x); }