Prints the positions of all set (1) bits in binary representation of x
| 8 | |
| 9 | // Prints the positions of all set (1) bits in binary representation of x |
| 10 | void print_on_bits(int x) { |
| 11 | for (int k = 0; k < 32; k++) { |
| 12 | if (check_kth_bit(x, k)) { |
| 13 | cout << k << ' '; // prints the position of the set bit |
| 14 | } |
| 15 | } |
| 16 | cout << '\n'; |
| 17 | } |
| 18 | |
| 19 | // Returns the count of set (1) bits in binary representation of x |
| 20 | int count_on_bits(int x) { |