Unit 2 - 2.2 - Integer Representation
Unit 2 - 2.2 - Integer Representation
1
Outline
• Integer Representation
• Binary Addition
• Binary Subtraction
• Binary Multiplication
• Booth’s Algorithm
2
Integer Representation
• Integer Representation refers to how the computer stores or represents a number in memory.
• The computer represents numbers in binary (1's and 0’s).
• As computer has a limited amount of space that can be used for each number or variable.
• This directly impacts the size, or range, of the number that can be represented.
• Computers uses a fixed number of bits to represent an integer.
• The commonly-used bit-lengths for integers are 8-bit, 16-bit, 32-bit or 64-bit.
• Besides bit-lengths, there are two representation schemes for integers:
1. Unsigned Integers: can represent zero and positive integers
2. Signed Integers: can represent zero, positive and negative integers
3
Integer
Signed
•Sign and Magnitude
•1’s Complement
•2’s Complement
Unsigned
4
Unsigned Integers
• Unsigned integers can represent zero and positive integers, but not negative integers. An n-bit
unsigned integer can represent integers from 0 to (2^n)-1
5
Signed Integers- Sign Magnitude Representation
6
0 and -0 ?
7
In sign magnitude representations, there are two different representations for 0.
8
1’s Complement Representation
9
Since the magnitude of both numbers is the same, the first 7 bits in the representation are the same for
both numbers. For +34, the MSB is 0, and for -34, the MSB or sign bit is 1
10
11
Binary Addition & Subtraction
12
Overflow
• On any addition, the result may be larger than can be held in the word size being used.
• This condition is called overflow. When overflow occurs, the ALU must signal this fact so that
no attempt is made to use the result.
• To detect overflow, the following rule is observed:
• OVERFLOW RULE: If two numbers are added, and they are both positive or both negative,
then overflow occurs if and only if the result has the opposite sign.
13
Hardware for Addition and Subtraction
14
Note that overflow can occur whether or not there is a carry.
15
SUBTRACTION RULE: To subtract one number (subtrahend) from another (minuend), take the twos
complement (negation) of the subtrahend and add it to the minuend
16
Multiplication
• Complex
• Work out partial product for each digit
• Take care with place value (column)
• Add partial products
17
Multiplication Example
1011 Multiplicand (11 dec)
x 1101 Multiplier (13 dec)
1011 Partial products
0000 Note: if multiplier bit is 1 copy
1011 multiplicand (place value)
1011 otherwise zero
10001111 Product (143 dec)
Note: need double length result
18
Unsigned Binary Multiplication
19
Flowchart for Unsigned Binary Multiplication
20
Multiplying Negative Numbers
21
Booth’s Algorithm
22
Example of Booth’s Algorithm
23
THANK YOU
24