Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ConsoleApplication1.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <iostream>
- #include <vector>
- #include <string>
- #include <algorithm>
- #include <sstream>
- #include <iterator>
- int _tmain(int argc, _TCHAR* argv[])
- {
- std::cout << "Decimal to Binary Conversion 1.0" << std::endl;
- std::cout << "\n";
- int decimalValue;
- std::cin >> decimalValue;
- std::vector<int> binaryDigits;
- bool conversion = true;
- int n = decimalValue;
- int b;
- std::cout << "Converting..." << std::endl;
- do{
- if(!n <= 0)
- {
- b = n % 2;
- binaryDigits.push_back(b);
- std::cout << ".";
- n = n/2;
- }
- else
- conversion = false;
- }while(conversion);
- std::cout << std::endl;
- std::cout << "Conversion Complete" << std::endl;
- std::string out(binaryDigits.rbegin(), binaryDigits.rend());
- std::cout << "The binary conversion of " << decimalValue << " is: ";
- for( std::vector<int>::reverse_iterator iter = binaryDigits.rbegin(); iter != binaryDigits.rend(); ++iter)
- std::cout << *iter;
- std::cout << std::endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement