Reputation: 471
Please don't tell me to convert the numbers to positive and attempt it as - X - = +
The number is -3 (101)
-3 X -3 = +9
How can this sum be done in binary?
Thanks.
Upvotes: 1
Views: 3118
Reputation: 111289
Negative integers are usually stored in 2's complement representation, which means that as an m-bit number -x is stored as 2m-x. This is where the name two's complement comes from: adding x results in a complete power of two.
Assuming we use 32 bits, -3 is stored as 232-3 = 4294967293.
So, -3 × -3 = 4294967293 × 4294967293 = 18446744047939747849. But this number doesn't fit into 32 bits. It overflows, and we are left with its last 32 bits. Those bits naturally encode the number 9.
You want to see it in binary? Ok. -3 is 232-3 is 111111111111111111111111111111012.
11111111111111111111111111111101×11111111111111111111111111111101 =
1111111111111111111111111111101000000000000000000000000000001001
(32 msb) (32 lsb)
The lowest 32 bits of the result are 000000000000000000000000000010012, which is the number 9.
Upvotes: 4
Reputation: 75205
You seem to be looking for methods to perform a multiplication for values expressed in 2's complement...
This web page from Karen Miller, at U. of Wisconsin provides several of these methods, including ones that do not require to first convert the numbers to their inverses.
Upvotes: 2