Comparing integers

Notes for next time:

You can check if the unsigned integer ‘a’ is greater than ‘b’ by adding the ones complement of ‘b’ to ‘a’ and testing carry.  A twos complement subtraction doesn’t work as a > 0 is always false.

Signed integers are similar but you first add 0x80000000 to both a and b.  This makes both unsigned without changing the order.

Avatar
Michael Hope
Software Engineer