Posted by : Sushanth Wednesday 16 December 2015

// BitwiseOperators.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include
using namespace std;
int main() {
/******************BITWISE AND -- & operator: ***********************
The bitwise AND operator (&) compares each bit of the first
operand to the corresponding bit of the second operand.
If both bits are 1, the corresponding result bit is set to 1.
Otherwise, the corresponding result bit is set to 0.
*******************************************************/
int a = 9; // 1001
int b=10; // 1010
cout<<(a & b)<<endl; //prints 8
/****************** Bitwise Exclusive OR : ^ operator: **********************
The bitwise exclusive OR operator (^) compares each bit of its first
operand to the corresponding bit of its second operand. If one bit is 0and the other bit
is 1, the corresponding result bit is set to 1.Otherwise, the corresponding result bit is
set to 0.f both bits are either 1 or 0,it is set to 0
***********************************************************************/
cout<<(a ^ b)<<endl; //prints 3
/****************** Bitwise Inclusive OR : | operator: ********************
The bitwise inclusive OR operator (|) compares each bit of its first operand
to the corresponding bit of its second operand. If either bit is 1, the
corresponding result bit is set to 1. Otherwise, the corresponding result
bit is set to 0.If both bits are 1,it is set to 1 .If both bits are 0,it
is set to 0
***********************************************************************/
cout<<(a|b)<<endl;
}

Leave a Reply

Subscribe to Posts | Subscribe to Comments

- Copyright © Technical Articles - Skyblue - Powered by Blogger - Designed by Johanes Djogan -