fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. // your code goes here
  6. int n1 = 15; // the binary is 00001111
  7. int n2 = 22; // the binary is 00010110
  8.  
  9. // calculate bitwise AND
  10. int r1 = n1 & n2; // binary: 00000110 (decimal 6)
  11.  
  12. // calculate logical AND
  13. int r2 = n1 && n2; // (nonzero) && (nonzero) is always 1
  14.  
  15. cout << "Operands: \n";
  16. cout << n1 << "\n";
  17. cout << n2 << "\n\n";
  18. cout << "Results: \n";
  19. cout << r1 << " (bitwise AND)\n";
  20. cout << r2 << " (logical AND)\n\n";
  21.  
  22. return 0;
  23. }
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
Operands: 
15
22

Results: 
6 (bitwise AND)
1 (logical AND)