What is Bitwise AND in C++?


The bitwise AND operator (&) compares each bit of first operand to the corresponding bit of second operand. If both bits are 1, the corresponding result bit is set to 1. Otherwise, the corresponding result bit is set to 0. Both operands to the bitwise inclusive AND operator must be of integral types. For example,

Example

#include <iostream>  
using namespace std;  

int main() {  
   unsigned short a = 0x5555;      // pattern 0101 ...  
   unsigned short b = 0xAAAA;      // pattern 1010 ...  
   cout << hex << ( a & b ) << endl;
}

Output

This gives the output −

0

Updated on: 11-Feb-2020

99 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements