I made a function to change from char to binary, but i can't show it with zero number in front of result.
Example: it show 10001 while I would like it show: 0010001
How can I do it?
Thanks!
Vietnamese semi pro ^^
I made a function to change from char to binary, but i can't show it with zero number in front of result.
Example: it show 10001 while I would like it show: 0010001
How can I do it?
Thanks!
Vietnamese semi pro ^^
>How can I do it?
Modify your code.
If you want help with your code, I would suggest that you post it.
7. It is easier to write an incorrect program than understand a correct one.
40. There are two ways to write error-free programs; only the third one works.*
You could make a string with as many 0's as you want
But i want to use it to calculate, so I can't change it to string
You can calculate and then convert and display as needed.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Calculate the length of your binary string. If it isn't the correct length then modify the string to include a couple more 0's.
My computer is awesome.
How is the converted binary value stored? Do you convert it and put it in an int? If it's purely a question of displaying the result with leading zeros, then you should be able to use the stream manipulator functions setw and setfill (along with maybe right... or is it left?) to achieve that result.
"Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
-Christopher Hitchens