HOW INTEGERS ARE STORED IN MEMORY USING TWO’S COMPLEMENT

Giovanny Andres Ortegon Espitia
2 min readAug 10, 2019

--

This is a method for representing a number with a sign(Negative). The complement of any binary number is to keep the most significative number and invert other digits.
For example:
We want to represent -2 in binary
2| 0010 apply two’s complement 1110
The two’s complement has the advantage that the fundamental arithmetic operations of addition, subtraction, and multiplication.
There is two representation of two’s complement according to bit numbers.

Sometimes the two’s complement can be ambiguous. For example, 0111 represents decimal 7 in 4bits the two’s complement is 1001 that in decimal is 9 but that really is -7 in two’s complement.

For example:

(-95)+ 1256

= (-95) + 255 + 1

= 255 -95 +1

= 160 + 1

= 161

Example addition aritmetic with one’s and two’s complememt

ADDITION

SUBTRACTION

--

--

No responses yet