...

/

Solution: Analyze the Output

Solution: Analyze the Output

The solution to the challenge, "Exercise: Analyze the Output".

We'll cover the following...

Solution

Press + to interact
#include <bit>
#include <bitset>
#include <iostream>
int main() {
std::cout << std::endl;
std::cout << std::boolalpha;
for (auto i = 0u; i < 16u; ++i) {
std::cout << "has_single_bit(" << std::bitset<8>(i) << ") = " << std::has_single_bit(i) << '\n';
std::cout << "bit_ceil(" << std::bitset<8>(i) << ") = " << std::bit_ceil(i) << '\n';
std::cout << "bit_width(" << std::bitset<8>(i) << ") = " << std::bit_width(i) << '\n';
std::cout << "bit_popcount(" << std::bitset<8>(i) << ") = " << std::popcount(i) << '\n';
std::cout << std::endl;
}
std::cout << std::endl;
}

Explanation

The loop runs for all numbers from 0u ...