Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- string odwroc(string liczba)
- {
- string wynik = "";
- for(int i = liczba.size() - 1; i >= 0; --i)
- wynik += liczba[i];
- return wynik;
- }
- int konwertuj_2_na_10(string liczba2)
- {
- liczba2 = odwroc(liczba2);
- unsigned n = liczba2.size();
- int wynik = 0;
- for(unsigned i = 0; i < n; ++i)
- if(liczba2[i] == '1')
- wynik += pow(2,i);
- return wynik;
- }
- int main()
- {
- cout << konwertuj_2_na_10("10110");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement