Method to find out the total number of bits in a number.
(int num)
| 10 | * Method to find out the total number of bits in a number. |
| 11 | **/ |
| 12 | public static int numberOfBits(int num){ |
| 13 | int countOfBits = 0; |
| 14 | |
| 15 | while(num != 0){ |
| 16 | num = num >> 1; |
| 17 | countOfBits++; |
| 18 | } |
| 19 | |
| 20 | return countOfBits; |
| 21 | } |
| 22 | } |