• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests
July 07, 2022 |50 Views
Check if one of the numbers is one’s complement of the other
  Share   Like
Description
Discussion

Given two non-negative integers a and b. The problem is to check if one of the two numbers is 1’s complement of the other. 
The ones’ complement of a binary number is defined as the value obtained by inverting all the bits in the binary representation of the number (swapping 0s for 1s and vice versa).

Examples:

Input : a = 10, b = 5
Output : Yes
(10)10 = (1010)2
1's complement of 10 is
= (0101)2 = (101)2 = (5)10

 

Check if one of the numbers is one’s complement of the other  : https://www.geeksforgeeks.org/check-one-numbers-ones-complement/

Read More