Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- //#include <string.h>
- using namespace std;
- int BinToDec(int binNumber) {
- int decimalValue = 0;
- int base1 = 1;
- while (binNumber > 0)
- {
- int reminder = binNumber % 10;
- binNumber = binNumber / 10;
- decimalValue += reminder * base1;
- base1 = base1 * 2;
- }
- return decimalValue;
- }
- int main()
- {
- char strExit = 'C';
- int bin = 0;
- do
- {
- cout << "Enter Binary Number\n";
- cin >> bin;
- cout << BinToDec(bin) << "\n";
- cout << "Press Q to exit, C to continue\n";
- cin >> strExit;
- if (strExit == 'Q') {
- break;
- }
- } while (true);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement