fork download
  1. #include <iostream>
  2. #include <bitset>
  3. using namespace std;
  4.  
  5. int main() {
  6. int liczba;
  7. cin >> liczba;
  8. // dec2u2 metoda 1 - dzielenie modulo i negacja
  9. string licz;
  10. int tmp = liczba;
  11. int tmp2;
  12.  
  13. if (liczba<0)
  14. tmp++;
  15. while(tmp)
  16. {
  17. licz = (tmp%2?"1":"0") + licz;
  18. tmp /=2;
  19. }
  20. licz = "0" + licz;
  21. if (liczba<0)
  22. {
  23. for(int i=0;i<licz.size(); i++)
  24. licz[i] = (licz[i]=='1'?'0':'1');
  25. }
  26. tmp2 = licz.size();
  27. for(int i=0;i<32-tmp2;i++)
  28. licz = licz[i]+licz;
  29.  
  30. cout << licz << endl;
  31.  
  32. // dec2u2 - meoda 2 - odczyt stanu bitów w pamięci
  33. for (int i=31;i>=0; i--){
  34. cout << (liczba&(1<<i)?1:0);
  35. }
  36.  
  37. cout << endl;
  38. // dec2u2 - metoda 3 - wykorzystanie rzutowania na bitset
  39. cout << bitset<32>(liczba);
  40.  
  41. // your code goes here
  42. return 0;
  43. }
Success #stdin #stdout 0s 3436KB
stdin
1
stdout
00000000000000000000000000000001
00000000000000000000000000000001
00000000000000000000000000000001