Menu Close

How the Negative Integer Numbers are Stored in Memory

Posted in C Programming, C++ Programming

Computer uses special mechanism to store negative numbers which is 2’s complement format.

Before going to that, let’s have a look on 1’s complement of a number.

1’s complement of a number

1’s compliment of number is just inverting binary bits of an actual number.

2’s complement of a number

To get 2’s complement of a number, just add 1 to 1’s complement of an actual number.

This 2’s complement form will be stored in computer. 

Both one’s complement and two’s complement can not change the sign bit (MSB)

When we declare a negative integer variable,

int i;
i=-10;

The memory will assign above memory for -10 ( 16 bit system )

Leave a Reply