Compared to positive values, the way how negative values get stored in the computer is completely different. Most computers today, use2's complement binary form to store a negative value. Let’s see how it’ll work.

consider, here I am storing -27 in this variable.

The equivalent binary of -27is the 2’s complement binary of its absolute value.

To get the absolute value of -27, just omit its sign i.e. you will get 27 as an absolute value.

To get 2’s complement binary value

  1. Find the equivalent binary of the absolute value.
  2. Find the one’s complement to the result of step1
  3. Add one to the 1’s complement binary result to get 2’s complement binary.

For example, here the absolute value of -27 is 27.

Step 1: The binary value of 27 is

Step 2: Find the one’s complement of this binary value.

Step 3: Add 1 to the one’s complement binary value, you will get the below two’s complement result.

This is the value that will get stored in the variable’s memory space.

Categorized in:

Tagged in: