Check if binary representation of a given number and its complement are anagram | An efficient C ++ program to check if binary representations of a number and it 's complement are anagram. ; Returns true if binary representations of a and b are anagram . ; _popcnt64 ( a ) gives number of 1 's present  in binary representation of a. If number  of 1s is half of total bits, return true. ; Driver code
#include <bits/stdc++.h> NEW_LINE #define ull  unsigned long long int NEW_LINE using namespace std ; const int ULL_SIZE = 8 * sizeof ( ull ) ; bool bit_anagram_check ( ull a ) { return ( _popcnt64 ( a ) == ( ULL_SIZE >> 1 ) ) ; } int main ( ) { ull a = 4294967295 ; cout << bit_anagram_check ( a ) << endl ; return 0 ; }