It is easy to determine whether two numbers have the same sign. The hint is to use the MSB (most significant bit) as the sign bit, then use bit-wise operations to help you determine whether two numbers have the same sign bit.
Multiplying a number by a sign is an expensive method to change the sign of a number. For example, recall the following code:
This code can be implemented by
The new implementation is a little less general and therefore longer.
However, there is no multiplication involved. Negating constants
such as
and
is easy and is done at compile time.
Determining whether a number is negative or not is also easy in
hardware (sign bit).