Hi! I'm learining c++, and for a project I need to work with binary numbers.
I already have a function that translates from Decimal to binary, but I need to auto fill with ceros until it is 8 characters long.
Example: 10 in decimal is translated as 1010, but I need it to be 00001010.
Setfill tool doesn't work as I need the integer to be 8 digits long to use it in another function (as far as I've understood Setfill only works at the "cout").
bitset already does this, you can set it to a decimal number and printing it will give leading zeros
is that ok, or do you need to recreate it for learning?
Setfill tool doesn't work as I need the integer to be 8 digits long to use it in another function (as far as I've understood Setfill only works at the "cout").
Digit count is a property of a representation, not of a number. Consider this:
10024
That's a representation. Here's another one:
23450
Yet another one:
Ten thousand and twenty four.
One more:
万二十四
All of them mean the same thing: the number 10024. The number itself doesn't have digits, it's just an abstract entity. Only its representations may have digits, and only some of them do.
In other words, if you need something with "digits" then binario() should not be returning an integer at all. It should most likely return a string containing the integer's representation.