Check if a Number is Odd or Even using Bitwise Operators | C ++ program to check for even or odd using Bitwise XOR operator ; Returns true if n is even , else odd ; n ^ 1 is n + 1 , then even , else odd ; Driver code
#include <iostream> NEW_LINE using namespace std ; bool isEven ( int n ) { if ( n ^ 1 == n + 1 ) return true ; else return false ; } int main ( ) { int n = 100 ; isEven ( n ) ? cout << " Even " : cout << " Odd " ; return 0 ; }