Answer the question
In order to leave comments, you need to log in
How to print numbers in binary system?
How to print numbers in binary system?
There is a vector with a large number of numbers of different lengths. It is necessary to display them in the binary system of calculus.
There was a variant with std::bitset, but a constant is used there. I saw boost::dynamic_bitset, but it's not stl
Answer the question
In order to leave comments, you need to log in
With the fmt lib, the output in binary is very simple:
fmt::print("{:b}", num);
If without lib, then you can write a function that prints a number in binary in 2 cycles. With the first cycle, find the position of the highest unit, with the second cycle, print the binary digits from the found highest down to zero.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question