• Courses
  • Tutorials
  • DSA
  • Data Science
  • Web Tech
July 07, 2022 |7.9K Views

Detect if two integers have opposite signs (Dynamic Programming)

Description
Discussion

Given two signed integers, write a function that returns true if the signs of given integers are different, otherwise false. For example, the function should return true -1 and +100, and should return false for -100 and -200. The function should not use any of the arithmetic operators. 


Let the given integers be x and y. The sign bit is 1 in negative numbers, and 0 in positive numbers. The XOR of x and y will have the sign bit as 1 iff they have opposite sign. In other words, XOR of x and y will be negative number number iff x and y have opposite signs. The following code use this logic. 
 

Detect if two integers have opposite signs (Dynamic Programming) : https://www.geeksforgeeks.org/detect-if-two-integers-have-opposite-signs/