- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

Suppose we have two numbers x and y we have to check whether the binary representation of x and y are anagram of each other or not.

So, if the input is like x = 9 y = 12, then the output will be True as binary representation of 9 is 1001 and binary representation of 12 is 1100, so these two are anagram of each other.

To solve this, we will follow these steps −

- if number of 1s in x and y are same, then
- return True

- return False

Let us see the following implementation to get better understanding −

def set_bit_count(num) : cnt = 0 while num: cnt += num & 1 num >>= 1 return cnt def solve(x, y) : if set_bit_count(x) == set_bit_count(y): return True return False x = 9 y = 12 print(solve(x, y))

9, 12

True

- Related Questions & Answers
- Java program to check if binary representations of two numbers are anagram
- Python program to check if binary representation of two numbers are anagram.
- Check if two strings are anagram of each other using C++
- Python Program to Check If Two Numbers are Amicable Numbers
- Check whether two strings are anagram of each other in Python
- Check if sum of divisors of two numbers are same in Python
- Golang Program to check if two numbers are Amicable Numbers
- Check if two list of tuples are identical in Python
- Check if two lists are identical in Python
- Check if leaf traversal of two Binary Trees is same in Python
- Python - Check if two strings are isomorphic in nature
- How to check if two numbers (m,n) are amicable or not using Python?
- Check if any anagram of a string is palindrome or not in Python
- Java Program to check whether two Strings are an anagram or not.
- Check if bits in range L to R of two numbers are complement of each other or not in Python

Advertisements