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;
- }
- string konwertuj_10_na_2(int liczba10)
- {
- string wynik = "";
- while(liczba10 > 0)
- {
- if(liczba10 % 2 == 1)
- wynik += '1';
- else
- wynik += '0';
- liczba10 /= 2;
- }
- return odwroc(wynik);
- }
- string int_to_string(int liczba)
- {
- string wynik = "";
- while(liczba > 0)
- {
- wynik += static_cast<char>(liczba % 10 + 48);
- liczba /= 10;
- }
- return odwroc(wynik);
- }
- int main()
- {
- int liczba = 104682;
- cout << int_to_string(liczba);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement