- 3

What is the code for decimal to binary conversion in cpp

3rd Sep 2018, 5:43 PM
Archana Berad
2 Respostas
+ 5
#include <iostream> #include <vector> using namespace std; int main() { int num = 12; vector<int> bin; cout << num << " = "; while(num > 0) { int rem = num % 2; bin.push_back(rem); num /= 2; } for(int i = bin.size() - 1; i >= 0; i--) cout << bin.at(i); return 0; }
3rd Sep 2018, 7:36 PM
blACk sh4d0w
blACk sh4d0w - avatar
+ 3
Looking for examples? visit SoloLearn Code Playground and type "binary" on the search bar, pick C++ from language filter menu to the right and you're good to go. https://www.sololearn.com/Codes/
3rd Sep 2018, 6:31 PM
Ipang