Check if one of the numbers is one 's complement of the other | Java implementation to check if one of the two numbers is one 's complement of the other ; function to check if all the bits are set or not in the binary representation of ' n ' ; all bits are not set ; if true , then all bits are set ; else all bits are not set ; function to check if one of the two numbers is one 's complement  of the other ; Driver function
import java . util . * ; import java . lang . * ; public class GfG { public static boolean areAllBitsSet ( long n ) { if ( n == 0 ) return false ; if ( ( ( n + 1 ) & n ) == 0 ) return true ; return false ; } public static boolean isOnesComplementOfOther ( long a , long b ) { return areAllBitsSet ( a ^ b ) ; } public static void main ( String argc [ ] ) { long a = 10 , b = 5 ; if ( isOnesComplementOfOther ( a , b ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }