In C++20 you'll be able to use std::format
to do this:
unsigned char a = -58;
std::cout << std::format("{:b}", a);
Output:
11000110
In the meantime you can use the {fmt} library, std::format
is based on. {fmt} also provides the print
function that makes this even easier and more efficient (godbolt):
unsigned char a = -58;
fmt::print("{:b}", a);
Disclaimer: I'm the author of {fmt} and C++20 std::format
.