Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <math.h>
- using namespace std;
- void bin_to_dec(string s)
- {
- int res = 0;
- int len = s.length();
- int *arr = new int[len];
- for (int i = 0; i < len; i++)
- {
- if (s[i] == '1')
- {
- arr[i] = 1;
- }
- if (s[i] == '0')
- {
- arr[i] = 0;
- }
- }
- for (int i = 0, j = len - 1; i < len, j >= 0; i++, j--)
- res = res + arr[i] * (int)pow(2, j);
- cout << "in dec " << res << endl;
- }
- int main()
- {
- string s = "";
- while (true)
- {
- cin >> s;
- bin_to_dec(s);
- }
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement