C++ Tutorial/Operators statements/bitwise operator

Материал из C\C++ эксперт
Перейти к: навигация, поиск

Bit operator keywords.

<source lang="cpp">#include <iostream>

  1. include <iomanip>
  2. include <iso646.h>

using namespace std; int main() {

  int a = 8, b = 22;
  cout << boolalpha 
       <<   "   a and b: " << ( a and b )
       << "\n    a or b: " << ( a or b )
       << "\n     not a: " << ( not a )
     << "\na not_eq b: " << ( a not_eq b )
       << "\na bitand b: " << ( a bitand b )
       << "\na bit_or b: " << ( a bitor b )
       << "\n   a xor b: " << ( a xor b )
       << "\n   compl a: " << ( compl a )
       << "\na and_eq b: " << ( a and_eq b )
       << "\n a or_eq b: " << ( a or_eq b )
       << "\na xor_eq b: " << ( a xor_eq b ) << endl;
   
  return 0;

}</source>

Bitwise operator keywords: bitand, bitor, xor, compl, and_eq, or_eq, xor_eq

<source lang="cpp">#include <iostream> using std::boolalpha; using std::cout; using std::endl; int main() {

  bool a = true;
  bool b = false;
  int c = 2;
  int d = 3;
  cout << boolalpha;
  cout << "a = " << a << "; b = " << b
     << "; c = " << c << "; d = " << d;
  cout << "\n\nBitwise operator keywords:";
  cout << "\nc bitand d: " << ( c bitand d );
  cout << "\nc bit_or d: " << ( c bitor d );
  cout << "\n   c xor d: " << ( c xor d );
  cout << "\n   compl c: " << ( compl c );
  cout << "\nc and_eq d: " << ( c and_eq d );
  cout << "\n c or_eq d: " << ( c or_eq d );
  cout << "\nc xor_eq d: " << ( c xor_eq d ) << endl;
  return 0;

}</source>

a = true; b = false; c = 2; d = 3
Bitwise operator keywords:
c bitand d: 2
c bit_or d: 3
   c xor d: 1
   compl c: -3
c and_eq d: 2
 c or_eq d: 3
c xor_eq d: 0