4 - CH11 - Computer Arithmetic
4 - CH11 - Computer Arithmetic
Chapter 11
Computer Arithmetic
Copyright © 2019, 2016, 2013 Pearson Education, Inc. All Rights Reserved
Arithmetic & Logic Unit (ALU)
• Part of the computer that actually performs arithmetic
and logical operations on data
• All of the other elements of the computer system are
there mainly to bring data into the ALU for it to process
and then to take the results back out
• Based on the use of simple digital logic devices that can
store binary digits and perform simple Boolean logic
operations
Copyright © 2019, 2016, 2013 Pearson Education, Inc. All Rights Reserved
Figure 11.1
ALU Inputs and Outputs
Copyright © 2019, 2016, 2013 Pearson Education, Inc. All Rights Reserved
Integer Representation
• In the binary number system arbitrary numbers can be
represented with:
– The digits zero and one
– The minus sign (for negative numbers)
– The period, or radix point (for numbers with a fractional
component)
Sign-magnitude representation
is the simplest form that
employs a sign bit
Copyright © 2019, 2016, 2013 Pearson Education, Inc. All Rights Reserved
Table 11.1
Characteristics of Twos Complement
Representation and Arithmetic
Range -2n-1 through 2n-1 - 1
Number of Representations
One
of Zero
Take the Boolean complement of each bit of the corresponding
Negation positive number, then add 1 to the resulting bit pattern viewed
as an unsigned integer.
Add additional bit positions to the left and fill in with the value
Expansion of Bit Length
of the original sign bit.
If two numbers with the same sign (both positive or both nega-
Overflow Rule tive) are added, then overflow occurs if and only if the result has
the opposite sign.
To subtract B from A, take the twos complement of B and add
Subtraction Rule
it to A.
Copyright © 2019, 2016, 2013 Pearson Education, Inc. All Rights Reserved
Table 11.2
Alternative Representations for 4-Bit Integers
Decimal Sign-Magnitude Twos Complement Biased
Representation Representation Representation Representation
+8 – – 1111
+7 0111 0111 1110
+6 0110 0110 1101
+5 0101 0101 1100
+4 0100 0100 1011
+3 0011 0011 1010
+2 0010 0010 1001
+1 0001 0001 1000
–0 0000 0000 0111
+0 1000 – –
–1 1001 1111 0110
–2 1010 1110 0101
–3 1011 1101 0100
–4 1100 1100 0011
–5 1101 1011 0010
–6 1110 1010 0001
–7 1111 1001 0000
–8 – 1000 –
Copyright © 2019, 2016, 2013 Pearson Education, Inc. All Rights Reserved
Hexadecimal Notation 1/2
• Binary digits are grouped into sets of four bits, called a nibble
• Each possible combination of four binary digits is given a symbol, as
follows:
0000 = 0 0100 = 4 1000 = 8 1100 = C
0001 = 1 0101 = 5 1001 = 9 1101 = D
0010 = 2 0110 = 6 1010 = A 1110 = E
0011 = 3 0111 = 7 1011 = B 1111 = F
• Because 16 symbols are used, the notation is called hexadecimal and
the 16 symbols are the hexadecimal digits
• Thus
2C16 = (216 * 161) + (C16 * 160)
= (210 * 161) + (1210 * 160) = 44
Copyright © 2019, 2016, 2013 Pearson Education, Inc. All Rights Reserved
Complement of Numbers
Two types of complements for base R number system: R's complement
and (R-1)'s complement
(R-1)’s Complement
Subtract each digit of a number from (R-1) 9 9 9
- 8 3 5
Example
9's complement of 83510 : 16410 1 6 4
1's complement of 10102 : 01012 (bit by bit complement operation)
1 1 1 1
(R)’s Complement - 1 0 1 0
Add 1 to the low order digit of its (R-1)’s complement 0 1 0 1
1 1 1 1 9 9 9
Example
10's complement of 83510 : 16410 + 1 = 16510 - 1 0 1 0 - 8 3 5
2's complement of 10102 : 01012 + 1 = 01102 0 1 0 1 1 6 4
+ 1 + 1
0 1 1 0 1 6 5
Copyright © 2019, 2016, 2013 Pearson Education, Inc. All Rights Reserved
Signed Numbers
Copyright © 2019, 2016, 2013 Pearson Education, Inc. All Rights Reserved
Other Decimal Codes
0 00 000 0000
1 01 001 0001
Gray Code
11 011 0011
10 010 0010
110 0110
111 0111
101 0101
100 0100
1100
1101
1111
1110
- The Gray code has a reflection property 1010
- Easy to construct a table without calculation
1011
- for any n : reflect case n-1 about a mirror at its
bottom and prefix 0 and 1 to top and bottom 1001
halves, respectively 1000
Copyright © 2019, 2016, 2013 Pearson Education, Inc. All Rights Reserved
Other Decimal Codes … Cont…
Copyright © 2019, 2016, 2013 Pearson Education, Inc. All Rights Reserved
Examples Decimal Codes-3
Convert the following into Excess-3 and convert its sum to 4-bit Binary.
1- (58.43)10
The decimal number is: 5 8 4 3
Add 3 to each bit +3 +3 +3 +3
Sum 8 11 7 6
4-Bit Binary 1000 1011 0111 0110
Copyright © 2019, 2016, 2013 Pearson Education, Inc. All Rights Reserved
In-Class Activity
Convert the following into Excess-3 and convert its sum to 4-bit
Binary.
(567)10
(789.456)10
Copyright © 2019, 2016, 2013 Pearson Education, Inc. All Rights Reserved
Figure 11.2
Use of a Value Box for Conversion between
Twos Complement Binary and Decimal
Copyright © 2019, 2016, 2013 Pearson Education, Inc. All Rights Reserved
Range Extension
• Range of numbers that can be expressed is extended by
increasing the bit length
Copyright © 2019, 2016, 2013 Pearson Education, Inc. All Rights Reserved
Negation
• Twos complement operation
– Take the Boolean complement of each bit of the integer (including
the sign bit)
– Treating the result as an unsigned binary integer, add 1
+18 = 00010010 (twos complement)
bitwise complement = 11101101
+ 1
11101110 = -18
Copyright © 2019, 2016, 2013 Pearson Education, Inc. All Rights Reserved
Negation Special Case 1
Copyright © 2019, 2016, 2013 Pearson Education, Inc. All Rights Reserved
Negation Special Case 2
Copyright © 2019, 2016, 2013 Pearson Education, Inc. All Rights Reserved
Figure 11.3
Addition of Numbers in Twos Complement
Representation
Copyright © 2019, 2016, 2013 Pearson Education, Inc. All Rights Reserved
Overflow Rule
Copyright © 2019, 2016, 2013 Pearson Education, Inc. All Rights Reserved
Subtraction Rule
Copyright © 2019, 2016, 2013 Pearson Education, Inc. All Rights Reserved
Figure 11.4: Subtraction of Numbers in Twos
Complement Representation (M − S)
Copyright © 2019, 2016, 2013 Pearson Education, Inc. All Rights Reserved
Figure 11.7
Multiplication of Unsigned Binary Integers
Copyright © 2019, 2016, 2013 Pearson Education, Inc. All Rights Reserved
Figure 11.10: Multiplication of Two Unsigned
4-Bit Integers Yielding an 8-Bit Result
Copyright © 2019, 2016, 2013 Pearson Education, Inc. All Rights Reserved
Figure 11.11: Comparison of Multiplication
of Unsigned and Twos Complement Integers
Copyright © 2019, 2016, 2013 Pearson Education, Inc. All Rights Reserved
Figure 11.15: Division of Unsigned Binary
Integers
Copyright © 2019, 2016, 2013 Pearson Education, Inc. All Rights Reserved
Figure 11.17: Restoring Twos Complement Division (7/3)
Copyright © 2019, 2016, 2013 Pearson Education, Inc. All Rights Reserved
Floating-Point
Significand
• The final portion of the word
• Any floating-point number can be expressed in many ways
Copyright © 2019, 2016, 2013 Pearson Education, Inc. All Rights Reserved
Fixed-Point Representation
Copyright © 2019, 2016, 2013 Pearson Education, Inc. All Rights Reserved
Figure 11.18: Typical 32-Bit Floating-Point Format
Copyright © 2019, 2016, 2013 Pearson Education, Inc. All Rights Reserved
Floating Point Number Representation
• With a fixed-point notation it is possible to represent a range of
positive and negative integers centered on or near 0
• Limitations:
Copyright © 2019, 2016, 2013 Pearson Education, Inc. All Rights Reserved
Copyright © 2019, 2016, 2013 Pearson Education, Inc. All Rights Reserved
Comparison between Fixed and Floating points
No. Fixed-Point Floating-Point
1 represent and manipulate represent and manipulate
integers for + and - rational/reasonable numbers
2 Numbers up to 16 bits Numbers up to 32 bits
(65,536) possible bit (4,294,967,296) possible bit patterns
patterns (216). (232).
3 Not wider range of values Much wider range of values
4 Not able to represent very Able to represent very small and very
small and very large large numbers
numbers
5 The gaps between adjacent The gaps between adjacent numbers
numbers always equal one are approximately ten million times
for small and large numbers
6 Ex.: 123.45, 1234.56, Ex.: 1.234567, 123456.7,
12345.67, etc 0.00001234567, 1234567000000000
Copyright © 2019, 2016, 2013 Pearson Education, Inc. All Rights Reserved
IEEE Standard 754
Standard was developed to
facilitate the portability of
programs from one
Most important floating-point
processor to another and to
representation is defined
encourage the development
of sophisticated, numerically
oriented programs
Copyright © 2019, 2016, 2013 Pearson Education, Inc. All Rights Reserved
IEEE 754-2008
• Defines the following different types of floating-point formats:
• Arithmetic format
– All the mandatory operations defined by the standard are supported by the
format. The format may be used to represent floating-point operands or results
for the operations described in the standard.
• Basic format
– This format covers five floating-point representations, three binary and two
decimal, whose encodings are specified by the standard, and which can be
used for arithmetic. At least one of the basic formats is implemented in any
conforming implementation.
• Interchange format
– A fully specified, fixed-length binary encoding that allows data interchange
between different platforms and that can be used for storage.
Copyright © 2019, 2016, 2013 Pearson Education, Inc. All Rights Reserved
Figure 11.21: IEEE 754 Formats
Copyright © 2019, 2016, 2013 Pearson Education, Inc. All Rights Reserved
Error Detecting Codes
• Parity System
- Simplest method for error detection
- One parity bit attached to the information
• Even Parity and Odd Parity
- Even Parity: One bit is attached so that the total number
of 1 bits is an even number
Copyright © 2019, 2016, 2013 Pearson Education, Inc. All Rights Reserved
Parity Bit Generation
Parity Bit Generation
For b6b5... b0 (7-bit information); even parity bit beven
beven = b6 ⊕ b5 ⊕ ... ⊕ b0
For odd parity bit
bodd = beven ⊕ 1 = b’even
Parity Generator Circuit
(even parity)
Parity Checker Circuit
Copyright © 2019, 2016, 2013 Pearson Education, Inc. All Rights Reserved
Parity Bit Example
Type of bit Successful transmission scenario
parity
A wants to send: 1001
A computes parity bit value: 1+0+0+1 = 0
Even parity A adds parity bit and sends: 10010
B receives: 10010
B computes parity: 1+0+0+1+0 = 0 (Even)
B reports correct transmission after observing expected
even result.
A wants to send: 1001
A computes parity bit value: 1+0+0+1 = 1
A adds parity bit and sends: 10011
Odd parity B receives: 10011
B computes parity: 1+0+0+1+1= 1 (Odd)
B reports correct transmission after observing expected
odd result.
Copyright © 2019, 2016, 2013 Pearson Education, Inc. All Rights Reserved
Copyright
This work is protected by United States copyright laws and is provided solely
for the use of instructions in teaching their courses and assessing student
learning. dissemination or sale of any part of this work (including on the
World Wide Web) will destroy the integrity of the work and is not permit-
ted. The work and materials from it should never be made available to
students except by instructors using the accompanying text in their
classes. All recipients of this work are expected to abide by these
restrictions and to honor the intended pedagogical purposes and the needs of
other instructors who rely on these materials.
Copyright © 2019, 2016, 2013 Pearson Education, Inc. All Rights Reserved