Advertisement
Josif_tepe

Untitled

Jul 4th, 2022
935
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <cstring>
  4. #include <algorithm>
  5. #include <stack>
  6. #include <fstream>
  7. using namespace std;
  8. typedef long long ll;
  9. void to_binary(int x) {
  10.     string r = "";
  11.     while(x) {
  12.         r += (x % 2) + '0';
  13.         x /= 2;
  14.     }
  15.     reverse(r.begin(), r.end());
  16.     cout << r << endl;
  17. }
  18. int main() {
  19.     int number = 21;
  20.     to_binary(number);
  21.     number |= (1 << 1);
  22.     cout << number << endl;
  23.     to_binary(number);
  24.    
  25.     number |= (1 << 3);
  26.     to_binary(number);
  27.    
  28.     cout << number << endl;
  29.     return 0;
  30. }
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement