0% found this document useful (0 votes)
8 views28 pages

Course 2

Uploaded by

Assfou Riban
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views28 pages

Course 2

Uploaded by

Assfou Riban
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 28

Computer_Structure_Course_2

Dr MESSAOUDI M.A.
Chapter_Three:
Arithmetic of signed
numbers

To assess the suitability of


different signed number
representations it is necessary to
investigate their use in arithmetic
operations, particularly in
addition and subtraction.
Unsigned Binary Numbers
• An n-bit binary number can have 2n distinct combinations.
• Minimum: 0, Maximum: 2n – 1.
• For example, for n=3, the 8 distinct combinations are:
000, 001, 010, 011, 100, 101, 110, 111 (0 to 23-1 = 7 in decimal).

Number of bits (n) Range of Numbers

4 0 to 24-1 (15)
8 0 to 28-1 (255)
16 0 to 216-1 (65,535)
32 0 to 232-1 (4,294,967,295)

3
Unsigned Binary Numbers
Decimal Unsigned Decimal Unsigned
binary binary
+0 0000 +8 1000
+1 0001 +9 1001
Unsigned Number +2 0010 +10 1010
Representation in 4 Bits +3 0011 +11 1011
+4 0100 +12 1100
+5 0101 +13 1101
+6 0110 +14 1110
+7 0111 +15 1111
4
Signed Integer Representation

• Many of the numerical data items that we use are signed


(positive or negative).
• Question:: How to represent sign?
• Three possible approaches:
a) Sign-magnitude representation
b) One’s complement representation
c) Two’s complement representation

5
Signed Integer Representation
Positive
Sign and 1’s Complement 2’s Complement
+N Integers -N
Magnitude N N*
(all systems)
+0 0000 -0 1000 1111 -------
+1 0001 -1 1001 1110 1111
+2 0010 -2 1010 1101 1110
+3 0011 -3 1011 1100 1101
+4 0100 -4 1100 1011 1100
+5 0101 -5 1101 1010 1011
+6 0110 -6 1110 1001 1010
+7 0111 -7 1111 1000 1001
-8 ------- ------- 1000
(a) Sign-magnitude Representation

• For an n-bit number representation:


• The most significant bit (MSB) indicates sign (0: positive, 1: negative).
• The remaining (n-1) bits represent the magnitude of the number.
• Range of numbers: – (2n-1 – 1) to + (2n-1 – 1)

bn-1 bn-2 b1 b0
Sign
Magnitude

• A problem: Two different representations for zero.


+0: 0 00..000 and -0: 1 00..000
7
(a) Sign-magnitude Representation
Decimal Sign- Decimal Sign-
magnitude magnitude
+0 0000 -0 1000
Sign-Magnitude +1 0001 -1 1001
Number +2 0010 -2 1010
Representation in 4 Bits
+3 0011 -3 1011
+4 0100 -4 1100
+5 0101 -5 1101
+6 0110 -6 1110
+7 0111 -7 1111

8
(a) Sign-magnitude Representation

Sign-magnitude Addition
(a) Sign-magnitude Representation

Sign-magnitude Addition
(a) Sign-magnitude Representation

Sign-magnitude Addition
(a) Sign-magnitude Representation

Sign-magnitude Subtraction
(a) Sign-magnitude Representation

Sign-magnitude Subtraction
(b) 1’s Complement Representation

• Basic idea:
• Positive numbers are represented exactly as in sign-magnitude form.
• Negative numbers are represented in 1’s complement form.
• How to compute the 1’s complement of a number?
• Complement every bit of the number (1 to 0, and 0 to 1).
• Most Significant Bit (MSB) will indicate the sign of the number (0:
positive, 1: negative).

14
(b) 1’s Complement Representation

Example for n=4 Decimal 1’s Decimal 1’s


complement complement
To find the representation of -4, +0 0000 -7 1000
first note that +1 0001 -6 1001

+4 = 0100 +2 0010 -5 1010


+3 0011 -4 1011
-4 = 1’s complement of
+4 0100 -3 1100
0100 = 1011
+5 0101 -2 1101
+6 0110 -1 1110
+7 0111 -0 1111
15
(b) 1’s Complement Representation
• Range of numbers that can be represented in 1’s complement:
Maximum :: + (2n-1 – 1)
Minimum ::  (2n-1 – 1)
• A problem (same as in sign magnitude):
Two different representations of zero.
+0  0 000….0
-0  1 111….1
• Advantage of 1’s complement representation:
• Subtraction can be done using addition.
• Leads to substantial saving in circuitry. 16
(b) 1’s Complement Representation

1’s Complement Addition


(b) 1’s Complement Representation

1’s Complement Addition


(c) 2’s Complement Representation

• Basic idea:
• Positive numbers are represented exactly as in sign-magnitude form.
• Negative numbers are represented in 2’s complement form.
• How to compute the 2’s complement of a number?
• Complement every bit of the number (1 to 0 and 0 to 1), and then add
one to the resulting number.
• MSB will indicate the sign of the number (0: positive, 1: negative).

19
(c) 2’s Complement Representation

Decimal 2’s Decimal 2’s


Example for n=4 complement complement
+0 0000 -8 1000
To find the representation of,
+1 0001 -7 1001
say, -4, first note that
+2 0010 -6 1010
+4 = 0100
+3 0011 -5 1011
-4 = 2’s complement of +4 0100 -4 1100
0100 = 1011 + 1
+5 0101 -3 1101
= 1100
+6 0110 -2 1110
+7 0111 -1 1111
20
(c) 2’s Complement Representation

• Range of numbers that can be represented in 2’s complement:


Maximum :: + (2n-1 – 1)
Minimum ::  2n-1
• Advantage of 2’s complement representation:
• Unique representation of zero.
• Subtraction can be done using addition.
• Leads to substantial saving in circuitry.
• Almost all computers today use 2’s complement representation for
storing negative numbers.

21
(c) 2’s Complement Representation

2’s Complement Addition

22
(c) 2’s Complement Representation

2’s Complement Subtraction

23
(c) 2’s Complement Representation

2’s Complement Subtraction

24
Overflow and Underflow

• Overflow occurs when an arithmetic operation yields a result that is


greater than the range’s positive limit of 2N-1 – 1

• Underflow occurs when an arithmetic operation yields a result that is


less than the range’s negative limit of -2N-1
Example : overflow

• 510 + 610 (4-bits 2’s complement)


• Note that 4 bits can store +7 to -8
5 0101
+ 6 + 0110
1110 1011  -510

11 ≠ -5 OVERFLOW
Example : underflow

• -510 - 710 (4-bits 2’s complement)


• Note that 4 bits can store +7 to -8
-5 1011
+ -7 + 1001
-1210 1 0100  410

-12 ≠ 4 UNDERFLOW

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy