- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Check if binary representations of two numbers are anagram in Python
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))
- Java program to check if binary representations of two numbers are anagram
- Python program to check if binary representation of two numbers are anagram.
- Java Program to Check if two strings 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 lists are identical in Python
- Check if leaf traversal of two Binary Trees is same in Python
- Check if two list of tuples are identical in Python
- Python - Check if two strings are isomorphic in nature
- Check if any anagram of a string is palindrome or not in Python
- How to check if two numbers (m,n) are amicable or not using Python?
- Java Program to check whether two Strings are an anagram or not.