B
B
Bogdan Zhuvak2020-07-30 01:16:04
C++ / C#
Bogdan Zhuvak, 2020-07-30 01:16:04

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

1 answer(s)
A
Anton Zhilin, 2020-07-30
@Anton3

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 question

Ask a Question

731 491 924 answers to any question