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 ^^
This is a discussion on Exact binary in C++ within the C++ Programming forums, part of the General Programming Boards category; I made a function to change from char to binary, but i can't show it with zero number in front ...
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.
C + C++ Compiler: MinGW port of GCC
Version Control System: Bazaar
Look up a C++ Reference and learn How To Ask Questions The Smart Way
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.
I used to be an adventurer like you... then I took an arrow to the knee.