The two's complement offers a way of displaying negative numbers in the binary system. In the module, the two's complement is used for the representation of negative integers. (Integer system).
Positive numbers are represented as two's components with a leading 0 (sign bit). They are not further encoded. Negative numbers are represented with a leading 1 (sign bit) and encoded as follows: all digits of the corresponding positive figure are negated. The value 1 is added to the result. Example of the conversion of the negative decimal figure -4(dec) in a two's complement:
Or more mathematically:
Is x is a negative number, x is represented as a two's complement (x(z))
with n digits as follows:
As the module, when set to ,,Integer system'' always works with Int32 (4 bytes), the byte sequences of negative numbers x (e.g. -112) can be calculated easily as follows: