+ 2

C++ output reversing

#include<iostream> using namespace std; int main() { int d, bin; cout<<"Enter decimal value"<<endl; cin>>d; do { bin = d%2; d = d/2; // binary cout<<bin; } while(d>=1); } // this is the code, here binary result for decimal value to be reversed because if i entered 8 in decimal it gives me 0001 in binary instead of 1000... so i want just to reverse the output of binary. please help me

2nd Apr 2022, 9:31 AM
Yousafse
Yousafse - avatar
3 Respostas
+ 4
G'day Yousafse have you done arrays yet? What about pre/post-increment/decrement? https://code.sololearn.com/c5b6MHlNXkpv/?ref=app
2nd Apr 2022, 11:17 AM
HungryTradie
HungryTradie - avatar
+ 5
Do you have to do this manually? you can if you want, use std::bitset which is available in <bitset> header. http://www.cplusplus.com/reference/bitset/bitset/
2nd Apr 2022, 9:38 AM
Ipang
+ 2
HungryTradie it's totally fine, very thanks!
2nd Apr 2022, 11:25 AM
Yousafse
Yousafse - avatar