MeehoweCK

Untitled

Apr 16th, 2023
626
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.45 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. string convert10to2(long long liczba)
  6. {
  7.     string wynik = "";
  8.     if(liczba < 0)
  9.         wynik = "-";
  10.  
  11.     while(liczba > 0)
  12.     {
  13.         if(liczba % 2 == 0)
  14.             wynik = "0" + wynik;
  15.         else
  16.             wynik = "1" + wynik;
  17.         liczba = liczba / 2;
  18.     }
  19.     return wynik;
  20. }
  21.  
  22. int main()
  23. {
  24.     long long liczba = 1245;
  25.     cout << convert10to2(liczba) << endl;
  26.     return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment