BITLIB is a library for bit handling. Integers are generally used for bit
handling. Thus, the problem is in how the integer is represented in bit string.
Furthermore, in some cases, it may be more convenient to handle a bit string as
a hexadecimal number rather than a decimal number. The HEXLIB library is
available for this purpose.
There are two method of expressing a signed integer within a computer: the
"absolute value representation" and the "complement
representation." The "absolute value representation" expresses
the absolute value of the integer in binary with a sign bit as the leading bit
(0 when positive and 1 when negative). This method is simple and easy to
understand. However, it has the setback that two representations exist for the
integer 0, that is 0 and -0.
The "complement representation" is defined in a slightly more complex manner, but it has been implemented in a majority of the computers.
As with the "absolute value representation," 0 or a positive integer is expressed by a signed 32-bit integer, which consists of a 31-bit binary number with a sign bit (0) at the lead, in the complement representation.
In contrast, a negative integer is represented by the absolute value of the complement of the integer with a leading sign bit (1). Although, generally, there are multiple definitions of a "complement," here, it is used to refer to the "two's complement in binary (true complement)." In this case, a complement of X. will be a "number when added to X will give a total of 2n," which is the same as a "number represented by reversing the 0 and 1 in each bit and adding 1 to the last digit."
In short, when a signed integer is thought of simply as a 32-bit (positive) binary number, including the sign bit, a negative integer N will be represented as 231+N (See table below). With this method, the range of integers that can be represented is from -231 to 231-1.
Internal Representation Numeric values 11111111 11111111 11111111 11111111 -1 11111111 11111111 11111111 11111110 -2 ....... . ....... . 10000000 00000000 00000000 00000000 -231 01111111 11111111 11111111 11111111 +231-1 ....... . ....... . 00000000 00000000 00000000 00000001 1 00000000 00000000 00000000 00000000 0
With this method of representation, an integer can be handled uniformly as a positive integer, including its sign, in addition and subtraction. Therefore, the configuration of the arithmetic circuit remains relatively simple, and so this representation is implemented in a majority of computers.
It can be seen from the above that, in a complement representation, there is a one-to-one correspondence between a bit string in internal representation and its value as an integer. Thus, integer-type variables are used for handling data as bit strings and not as numbers.