Check whether two numbers differ at one bit position only
Submissions: 1345   Accuracy:

29.09%

  Difficulty: Basic   Marks: 1

Given two non-negative integers a and b. The problem is to check whether the two numbers differ at one bit position only or not.

Examples:

Input : a = 13, b = 9
Output : 1
(13)10 = (1101)2
(9)10 = (1001)2
Both the numbers differ at one bit position only, i.e,
differ at the 3rd bit from the right.

Input : a = 15, b = 8
Output : 0

INPUT : The first line contains an integer T i.e. the number of test cases.First and last line of each test case consists of two integers n and m.
OUTPUT : If given numbers n and m differ at single bit position then print "1" otherwise print "0".

CONSTRAINTS:
1<=T<=200
1<=n,m<=10

EXAMPLES:
INPUT:

1
13 9
OUTPUT:
1

** For More Input/Output Examples Use 'Expected Output' option **

Author: saksham0751


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.