C Programming Code Examples C > Bitwise Operators Code Examples C Program to find the Highest Bit Set for any given Integer C Program to find the Highest Bit Set for any given Integer #include <stdio.h> #define j_bits sizeof(int)*8 int highest_bit_set(int); void display(int); int i = j_bits; void main() { int j, pos; printf("\nenter the number:"); scanf("%d", &j); display(j); pos = highest_bit_set(j); printf("\nthe position of the highest bit set is %d", pos); } /* returns the position */ int highest_bit_set(int j) { int count = 0; while (j >> 1 != 0) { count++; j = j >> 1; } return(count); } /* displays the number in binary representation */ void display(int j) { int c; c = j & 1; if (i > 0) { i--; display(j >> 1); } printf("%d", c); }