Two's complement

Two's complement is the most common method of representing signed (positive, negative, and zero) integers on computers,[1] and more generally, fixed point binary values. Two's complement uses the binary digit with the greatest value as the sign to indicate whether the binary number is positive or negative; when the most significant bit is 1 the number is signed as negative and when the most significant bit is 0 the number is signed as positive. As a result, non-negative numbers are represented as themselves: 6 is 0110, zero is 0000, and -6 is 1010 (~6 + 1). Note that while the number of binary bits is fixed throughout a computation it is otherwise arbitrary.

Unlike the ones' complement scheme, the two's complement scheme has only one representation for zero. Furthermore, arithmetic implementations can be used on signed as well as unsigned integers[2] and differ only in the integer overflow situations.

  1. ^ E.g. "Signed integers are two's complement binary values that can be used to represent both positive and negative integer values.", Section 4.2.1 in Intel 64 and IA-32 Architectures Software Developer's Manual, Volume 1: Basic Architecture, November 2006
  2. ^ Bergel, Alexandre; Cassou, Damien; Ducasse, Stéphane; Laval, Jannik (2013). Deep into Pharo (PDF). p. 337.

Developed by StudentB