Search This Blog

Sunday, October 5, 2014

WAP to display all set bit position in a given 32-bits number

1:  main()  
2:  {  
3:    int i = 0x1234,pos = 1;  
4:    while(i)  
5:    {  
6:      if ( i & 0x01)  
7:      {  
8:        printf("%d\n",pos);  
9:      }  
10:      i = i>>1;  
11:      pos++;  
12:    }  
13:  }   

No comments:

Post a Comment