MCPcopy Create free account
hub / github.com/ShahjalalShohag/code-library / print_on_bits

Function print_on_bits

Basics/Bitwise Operations.cpp:10–17  ·  view source on GitHub ↗

Prints the positions of all set (1) bits in binary representation of x

Source from the content-addressed store, hash-verified

8
9// Prints the positions of all set (1) bits in binary representation of x
10void 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
20int count_on_bits(int x) {

Callers 1

mainFunction · 0.85

Calls 1

check_kth_bitFunction · 0.85

Tested by

no test coverage detected