Given two integers A & B. Task is to check if A and B are same or not without using comparison operators.
Input : A = 5 , B = 6 Output : 0 Input : A = 5 , B = 5 Output : 1 Note : 1 = "YES" and 0 = "NO"
idea is pretty simple we do Xor of both element ( A , B ) . if Xor is zero then two number are equal else not .
Below is the implementation of above idea :
This article is contributed by Nishant Singh. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Smallest of three integers without comparison operators
- Divide two integers without using multiplication, division and mod operator
- Check if two numbers are equal without using comparison operators
- Check if two numbers are equal without using arithmetic and comparison operators
- Find XOR of two number without using XOR operator
- Check a number is odd or even without modulus operator
- Multiply any Number with 4 using Bitwise Operator
- Multiply a number with 10 without using multiplication operator
- Multiplication of two numbers with shift operator
- Maximum OR value of a pair in an Array without using OR operator
- Find the remainder when N is divided by 4 using Bitwise AND operator
- Multiplying a variable with a constant without using multiplication operator
- Find largest element from array without using conditional operator
- Find two integers A and B such that A ^ N = A + N and B ^ N = B + N
- Hamming distance between two Integers
- How to sum two integers without using arithmetic operators in C/C++?
- Check if the XOR of an array of integers is Even or Odd
- Detect if two integers have opposite signs
- Sum of consecutive bit differences of first N non-negative integers
- Bitwise recursive addition of two integers