Next: Integers in Memory Up: Computer Representation of Numbers Previous: The Memory Model   Contents

# Reprentation of Signed Integers

binary digits (bits) of memory can store different numbers. They can be positive integers between and . For example, using bits, we can represent any integer between and .

If we want to represent signed integers (i.e. both positive and negative numbers) using bits, we can use one of the following methods:

• Sign/Magnitude representation. Reserve the first bit for the signum (for example, let 0 denote positive numbers, and 1 negative numbers); the other bits will store the magnitude (the absolute value) of the number. In this case the range of numbers represented is to . With there are bits for the magnitude, different possible magnitudes, between and ; each of these can have a positive and negative sign. Note that with this representation we have both positive and negative zero. If we make the convention that the sign bit is 1 for negative numbers we have
 Number ([S]M) -3 [1]11 -2 [1]10 -1 [1]01 -0 [1]00 +0 [0]00 +1 [0]01 +2 [0]10 +3 [0]11

• Two's complement representation. All numbers from to are represented by the smallest positive integer with which they are congruent modulo . With , for example, we have
 Number (2C) (2C) -4 4 100 -3 5 101 -2 6 110 -1 7 111 0 0 000 1 1 001 2 2 010 3 3 011
Note that the first bit is 1 for negative numbers, and 0 for nonnegative numbers.

• Biased representation. A number is represented by the positive value . Adding the bias gives positive results.
 Number (biased) (biased) -4 0 000 -3 1 001 -2 2 010 -1 3 011 0 4 100 1 5 101 2 6 110 3 7 111
The first bit is 0 for negative numbers, and 1 for nonnegative numbers.

Subsections

Next: Integers in Memory Up: Computer Representation of Numbers Previous: The Memory Model   Contents