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 ^^
Printable View
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.
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.
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.
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.