aboutsummaryrefslogtreecommitdiffstats
path: root/test/gourdinl/c/msb_pos.c
blob: f2e7fe092efa454144aa9680389ca84fbb0d146c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/* Function to find the MSB bit position */
int main(int n)
{
  int i = 0, bit;
  while (i < 32)
  {
     bit = n & 0x80000000;
     if (bit == -0x80000000)
     {
        bit = 1;
     }

     if (bit == 1) 
       break;

      n = n << 1;
      i++;
  }
  return i;
}