Which arithmetic operations are the same on unsigned and two’s complement signed numbers?

Addition, subtraction and multiplication are the same provided: Your inputs and outputs are the same size Your behaviour on overflow is wraparound modulo 2n Division is different. Many instruction sets offer multiplication operations where the output is larger than the input, again these are different for signed and unsigned. Furthermore if you are writing your … Read more

Why prefer two’s complement over sign-and-magnitude for signed numbers?

It’s done so that addition doesn’t need to have any special logic for dealing with negative numbers. Check out the article on Wikipedia. Say you have two numbers, 2 and -1. In your “intuitive” way of representing numbers, they would be 0010 and 1001, respectively (I’m sticking to 4 bits for size). In the two’s … Read more