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.
- 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
- Multiply a number with 10 without using multiplication operator
- Multiplication of two numbers with shift operator
- Check a number is odd or even without modulus operator
- Multiply any Number with 4 using Bitwise Operator
- Multiplying a variable with a constant without using multiplication operator
- Hamming distance between two Integers
- How to sum two integers without using arithmetic operators in C/C++?
- Find largest element from array without using conditional operator
- Detect if two integers have opposite signs
- Bitwise recursive addition of two integers