Two's Complement Representation: Difference between revisions
Line 18: | Line 18: | ||
v = -a<sub>n-1</sub>*2<sup>n-1</sup> | v = -a<sub>n-1</sub>*2<sup>n-1</sup>+∑<sup>n-2</sup><sub>i=0</sub> | ||
=Practical Implications= | =Practical Implications= |
Revision as of 00:30, 6 April 2020
External
Internal
Overview
Two's complement is the most common signed integer representation scheme on computers. The scheme is widely used because a computer can use the same circuitry to perform addition, subtraction and multiplication, whereas otherwise they would have to be treated as separate operations. Also, two's complement has no representation for negative zero, and thus does it not suffer from associated difficulties.
Mathematical Foundation
A two's complement encodes both positive and negative numbers in a binary number representation. Assuming that n bits are available to represent an integral value, the weight of each bit, except the most significant one, is a power of two. The weight of the most significant bit is the negative of the corresponding power of two.
an-1 an-2 ... a2 a1 a0
v = -an-1*2n-1+∑n-2i=0
Practical Implications
Subtraction
used by most computers to represent signed integral values such as byte, int or long.
Positive numbers
Negative numbers
The primary motivation between this scheme is that