I have a problem in this C++ program That i have written. help me with the problem that i have mentioned below
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 <iostream>
#include <cmath>
using namespace std;
int main ()
{
unsigned int a;
unsigned int y;
a=16;
y=a%2;
a=a/2;
while((a)!=0)
{
cout<<y;
y=a%2;
a=a/2;
}
cout<<y<<endl;
return 0;
}
If you dont understand any part of my question or my program u can ask me
I recently got an idea would it be better to use a bitwise operator
if so can you guide me a bit on using it and the function that i can use
be more specific in wut fuction can i use as bitwise and how can i use it