Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- #include <algorithm>
- using namespace std;
- int main() {
- cout << "Enter decimal number: ";
- int denary;
- cin >> denary;
- int tempDenary = denary;
- vector<int> binary;
- // Turn denary into binary
- while (tempDenary >0) {
- if (tempDenary % 2 == 0) {
- binary.push_back(0);
- tempDenary = tempDenary / 2;
- }
- if (tempDenary % 2 == 1) {
- binary.push_back(1);
- tempDenary = tempDenary / 2;
- }
- }
- cout << binary[0];
- cout << binary[1];
- cout << binary[2];
- cout << binary[3];
- cout << binary[4];
- cout << binary[5];
- /*
- for (int i = 0; i < size; i++) {
- cout << binary[i];
- }
- */
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement