how to reverse the output in c++
hi!
there is a c++ programe to convert a decimal number into binary.i have somehow done it but the output is in reverse order.that is if we take input 4 then the answers should be 100 but it gives 001.plz guide me what to do?
there is a c++ programe to convert a decimal number into binary.i have somehow done it but the output is in reverse order.that is if we take input 4 then the answers should be 100 but it gives 001.plz guide me what to do?
0
Comments
This masks off all the individual bits, and tests if' the result is zero. If it is, that bit is a zero.
main()
{
int n,r;
cout<<"enter the integer";
cin>>n;
while(n>=1)
{
r = n % 2;
n = n/2;
cout<<r;
}
}
>
this is the code,with which i have tried to solve the problem but...
Be carefull of the big-endian/little-endian difference on machines. You might get;
000000000000001000000000000000000
when you want
00000000000000000000000000000100
sarah - The only way I can think of to solve the code using the way that you're working on it is to store the values in a temporary string, and then print it after you're done.
main()
{
int n,r;
cout<<"enter the integer";
cin>>n;
while(n>=1)
{
r = n % 2;
n = n/2;
cout<<"r;
}
}
>