Count numbers whose XOR with N is equal to OR with N | C ++ program to find the XOR equals OR count ; Function to calculate count of numbers with XOR equals OR ; variable to store count of unset bits ; Driver code
#include <iostream> NEW_LINE #include <math.h> NEW_LINE using namespace std ; class gfg { public : int xorEqualsOrCount ( int N ) { int count = 0 ; int bit ; while ( N > 0 ) { bit = N % 2 ; if ( bit == 0 ) count ++ ; N = N / 2 ; } return ( int ) pow ( 2 , count ) ; } } ; int main ( ) { gfg g ; int N = 7 ; cout << g . xorEqualsOrCount ( N ) ; return 0 ; }