Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- int main(int argc, const char * argv[]) {
- cout << "Input your binary number: " << endl;
- string numberSTR;
- cin >> numberSTR;
- int decimalNumber = 0;
- int count = 0;
- for (size_t x = numberSTR.size(); x > 0; x--) {
- char binary = numberSTR[count];
- if (binary == '1') {
- int sizeS = int(x);
- decimalNumber += pow(2, sizeS-1);
- }
- count++;
- }
- cout << numberSTR << " corresponds to " << decimalNumber << " in decimal notation." << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment