1
votes

I'm really confused about the term "32-bit twos complement"

If I have the number 9, what is the 32-bit twos complement?

9 = 1001

Two's complement = 0111

32-bit 9 = 0000 0000 0000 0000 0000 0000 0000 1001

Two's complement = 1111 1111 1111 1111 1111 1111 1111 0111

That result is so ridiculous! It's way too large! Is that really how you're supposed to do it?

1
its not any larger then any other 32-bit numbercmd

1 Answers

1
votes

The most common format used to represent signed integers in modern computers is two's complement. Two's complement representation allows the use of binary arithmetic operations on signed integers.

Positive 2's complement numbers are represented as the simple binary.

Negative 2's complement numbers are represented as the binary number that when added to a positive number of the same magnitude equals zero.

Your 2's complemented output is equivalent to -9 (negative 9).

Edited:

You are asked to perform 32-bit operation hence it should be 1111 1111 1111 1111 1111 1111 1111 0111

For signed number, leftmost bit represents the sign of the number. If leftmost bit (LSB) is 1 then the number is negative otherwise it's positive. So, your 32-bit 2's complemented number is negative and it's -9. Simply, performing 2's complement on a number is equivalent to negating it i.e. it makes a positive number into negative and vice versa. For more browse the link:

http://www.tfinley.net/notes/cps104/twoscomp.html