Signed and Unsigned Numbers
Signed and Unsigned Numbers
Signed and Unsigned Numbers
UNSIGNED
NUMBERS
Prepared by
K.NITHYANANTHAN
binary digit Also called binary bit. One of the two numbers in base 2, 0 or 1, that are the
components of information.
Generalizing the point, in any number base, the value of i th digit d is
d ×𝐵𝑎𝑠𝑒𝑖
For example,
1011 2
represents
(1 x 23 ) + (0 x 22 ) + (1 x 21 ) + (1 x 20 )ten
= (1 x 8) + (0 x 4) + (1 x 2) + (1 x 1)ten
= 8 + 0 + 2 + 1ten
= 11ten
The drawing below shows the numbering of bits within a MIPS word and the placement of the
number 1011two:
The MIPS word is 32 bits long, so we can represent 232 different 32-bit patterns.
It is natural to let these combinations represent the numbers from 0 to 232 −1
(4,294,967,295ten):
That is, 32-bit binary numbers can be represented in terms of the bit value times a power of 2 (here xi
means the ith bit of x):
Computer programs calculate both positive and negative numbers, so we need a representation
that distinguishes the positive from the negative.
solution is to add a separate sign, which conveniently can be represented in a single bit;
the name for this representation is sign and magnitude.
sign and magnitude representation has several shortcomings
To the right? To the left ? Early computers tried both.
adders for sign and magnitude may need an extra step to set the sign because we can’t
know in advance what the proper sign will be.
separate sign bit means that sign and magnitude has both a positive and a negative zero,
which can lead to problems for inattentive programmers.
the representation that made the hardware simple: leading 0s mean positive, and leading 1s mean
negative. This convention for representing signed binary numbers is called two’s complement
representation:
The positive half of the numbers, from 0 to 2,147,483,647ten (231 −1), use the same
representation as before.
The following bit pattern (1000 . . . 0000two) represents the most negative number
2,147,483,648ten ( −231 ). It is followed by a declining set of negative numbers:
2,147,483,647ten (1000 . . . 0001two) down to -1ten (1111 . . . 1111two).
Two’s complement representation has the advantage that all negative numbers have a 1 in
the most significant bit.
Consequently, hardware needs to test only this bit to see if a number is positive or negative
(with the number 0 considered positive). This bit is often called the sign bit.
By recognizing the role of the sign bit, we can represent positive and negative 32-bit
numbers in terms of the bit value times a power of 2:
Binary to Decimal Conversion
What is the decimal value of this 32-bit two’s complement number?