Josif_tepe

Untitled

Feb 18th, 2026
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <map>
  4. using namespace std;
  5. const long long MOD = 1e9 + 7;
  6. int n;
  7. string to_binary(int x) {
  8.     string res = "";
  9.     while(x > 0) {
  10.         res += (x % 2) + '0';
  11.         x /= 2;
  12.     }
  13.     while((int) res.length() < n) {
  14.         res += "0";
  15.     }
  16.     reverse(res.begin(), res.end());
  17.     return res;
  18. }
  19. int main() {
  20.    
  21.     int a = 54;
  22.     int b = 32;
  23.    
  24.     cout << to_binary(a) << endl;
  25.     cout << to_binary(b) << endl;
  26.    
  27.     cout << to_binary(a & b) << endl;
  28.    
  29.     cout << (a & b) << endl;
  30.    
  31.    
  32.     return 0;
  33. }
  34.  
Advertisement
Add Comment
Please, Sign In to add comment