asked 148k views
0 votes
How are negative numbers handled with "twos complement" notation?

asked
User Nevosial
by
8.3k points

1 Answer

3 votes

Final answer:

Negative numbers are handled in computers using two's complement notation, where the bits of the number's absolute value are inverted and 1 is added to the least significant bit to obtain the negative representation in binary.

Step-by-step explanation:

Negative numbers are represented in a computer system using two's complement notation. This is typically used to allow for negative values in binary, which otherwise has no native concept of a negative sign like in decimal notation.

To find the two's complement of a negative number, invert all bits of its absolute value in binary form (this is also known as taking the one's complement) and then add 1 to the least significant bit. For example, to find the two's complement of -5 in an 8-bit system:

  1. Write the binary representation of the positive number (5 in decimal is 00000101 in binary).
  2. Invert the bits (00000101 becomes 11111010).
  3. Add 1 to the inverted number (11111010 + 1 becomes 11111011).

The result, 11111011, is the two's complement representation of -5. To confirm, if we add 5 (00000101) to -5 (11111011) in binary, the result is 100000000, but since we are using an 8-bit system, we discard the carry and are left with 00000000, which represents 0, demonstrating that the two's complement representation is correct.

answered
User Mudar
by
7.4k points
Welcome to Qamnty — a place to ask, share, and grow together. Join our community and get real answers from real people.