- 3
What is the code for decimal to binary conversion in cpp
2 Answers
+ 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;
}
+ 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/