I have written this program to convert a integer to binary digit
problem one is that the binary conversion that i get is inverse i.e
if the conversion for 16 is
10000
but this program will output it as
00001
wut function can i use to convert my answer 00001 into 10000
should i use strings fuction get the length of the line than extact each string and use it to get 10000
Or is there a easy way that i can use
but i think the way i did is fine but the problem is that i am getting inverse answer waiting to hear from you thank u
#include %26lt;iostream%26gt;
#include %26lt;cmath%26gt;
using namespace std;
int main ()
{
unsigned int a;
unsigned int y;
a=16;
y=a%2;
a=a/2;
while((a)!=0)
{
cout%26lt;%26lt;y;
y=a%2;
a=a/2;
}
cout%26lt;%26lt;y%26lt;%26lt;endl;
return 0;
}I have written this C++ program but i have 2 problems with this it works just fine but, if you can help me?
Use a integer to string conversion and it will display properly. I had the same problem one time and it worked.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment