Lectures/Lect 2 - Arith op and codes

Download Report

Transcript Lectures/Lect 2 - Arith op and codes

Arithmetic Operators
Decimal Codes
9/15/09 - L2
Copyright 2009 - Joanne DeGroat, ECE, OSU
1
Class 2 outline

Number Ranges
Arithmetic Operators
Decimal Codes

Material from sections 1-3 and 1-4 of text


9/15/09 - L2
Copyright 2009 - Joanne DeGroat, ECE, OSU
2
Number Ranges

What do you mean by number range?



On paper you have as many digits as you can fit.
In a computer or digital system, it is built with a
limit to the number of bits that can be in a
number.
So the maximum number that can be represented
is limited by the number of bits


9/15/09 - L2
m bits allows representation of 2m numbers,
Ranged 0 through 2m -1
Copyright 2009 - Joanne DeGroat, ECE, OSU
3
Numbers ranges with binary

With 1 bit – 21 = 2 numbers


With 2 bits – 22 = 4 numbers




0 and 1
0, 1, 2, 3 (00, 01, 10, 11)
Or in fixed point 0, .5, 1, 1.5
Or in fractional 0, .25, .5, .75
With 3 bits – 23 = 8 numbers (Octal)

9/15/09 - L2
0,1,2,3,4,5,6,7 (000,001,010,011,100,101,110,111)
Copyright 2009 - Joanne DeGroat, ECE, OSU
4
Other number ranges

With 4 bits – Hex – 24 = 16 numbers


With 8 bits – 256 – commonly referred to as a
byte


0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F
0 through (28-1), or 0 through 255
With 16 bits

9/15/09 - L2
0 through (216-1), or 0 through 65,535 if the 16
bits represent and unsigned number
Copyright 2009 - Joanne DeGroat, ECE, OSU
5
Arithmetic Operators



Arithmetic in any base is according to the
same rules
Just must be careful to only use the r digits of
the radix.
Rules for binary addition are the same as for
base 10.
9/15/09 - L2
Copyright 2009 - Joanne DeGroat, ECE, OSU
6
Addition

Basic – consider the bit by bit possibilities




Augend
Addend
Sum
0
0
0
0
1
1
1
0
1
1
1
10
1
0
0
1
1 1 1
0 1 1
1 0 1
10 10 11
And including a carry




9/15/09 - L2
Carry
Augend
Addend
Sum
0
0
0
0
0
0
1
1
0
1
0
1
0
1
1
10
Copyright 2009 - Joanne DeGroat, ECE, OSU
7
Result carry


For those instances where the result was 10 or
11, the msb 1 of this addition are a carry into
the next bit position.
Muti-bit example




9/15/09 - L2
Carries
Augend
Addend
Sum
01100
00101
10001
12
5
17
Copyright 2009 - Joanne DeGroat, ECE, OSU
8
Result carry


For those instances where the result was 10 or
11, the msb 1 of this addition are a carry into
the next bit position.
Muti-bit example




9/15/09 - L2
Carries
Augend
Addend
Sum
11000
01100
00101
10001
12
5
17
Copyright 2009 - Joanne DeGroat, ECE, OSU
9
Binary Subtraction

Just like subtraction in any other base




Minuend
Subtrahand
Difference
10110
- 10010
00100
And when a borrow is needed. Note that the
borrow gives us 2 in the current bit position.
9/15/09 - L2
Copyright 2009 - Joanne DeGroat, ECE, OSU
10
Binary subtraction (cont)

And more ripple -
9/15/09 - L2
Copyright 2009 - Joanne DeGroat, ECE, OSU
11
Binary Multiplication

Just like base 10, it is a series of adds
5
x 3
9/15/09 - L2
Copyright 2009 - Joanne DeGroat, ECE, OSU
15
x 15
12
Operations in other bases


Operations in octal and hex follow the same
rules.
Book provides and example of octal
multiplication
9/15/09 - L2
Copyright 2009 - Joanne DeGroat, ECE, OSU
13
Conversion from Decimal

To binary (the most common)


Have seen one method so far
A General Procedure



9/15/09 - L2
Step 1 – Separate into integer and fractional parts
if there is a binary point
Repeat: Divide by radix, r, until remainder is <r
The final remainder is the msb.
Copyright 2009 - Joanne DeGroat, ECE, OSU
14
Example of conversion

Convert 5410 to binary
9/15/09 - L2
Copyright 2009 - Joanne DeGroat, ECE, OSU
15
Another example

Convert 4210 to binary

Book also show fractional conversion
9/15/09 - L2
Copyright 2009 - Joanne DeGroat, ECE, OSU
16
Decimal codes



We are cavemen at heart and like base 10.
Computer electronics are such that it likes
base 2.
IS THERE A COMPROMISE?


9/15/09 - L2
Binary Coded Decimal (BCD)
Group the binary into groups of 4 bits. Each
group can represent 16 distinct symbols. Use
only the 10 digits.
Copyright 2009 - Joanne DeGroat, ECE, OSU
17
BCD example


56 + 42
Encode as BCD digits



56 = 0101 0110
42 = 0100 0010
Simply do the binary addition of each BCD
digit

9/15/09 - L2
98 = 1001 1000
Copyright 2009 - Joanne DeGroat, ECE, OSU
18
Another example


46 + 68
Encode as BCD digits



46 = 0100 0110
68 = 0110 1000
Simply do the binary addition of each BCD
digit

9/15/09 - L2
?? = 1010 1110 but both are out of the
useable BCD representation range
Copyright 2009 - Joanne DeGroat, ECE, OSU
19
What to do?

Starting with least significant digit add 6





Had the bcd representation 1010 1110
Add 6 or 0110
to the 1110
Getting 10100 and have BCD digit 0100 and a
carry to the next BCD position
WHY 6?
9/15/09 - L2
Copyright 2009 - Joanne DeGroat, ECE, OSU
20
Add in the carry

Continue by adding the carry to the next digit






Had the bcd representation 1010 1110
Add the carry and get 1011 so must again add 6
Or add 0110
to the 1011
Getting 10001 and have BCD digit 0001 and a
carry to the next BCD position
Final answer is 0001 0001 0100 or 114 √
9/15/09 - L2
Copyright 2009 - Joanne DeGroat, ECE, OSU
21
Class 2 wrapup

Covered sections 1-3 and 1-4
Problems for hand in
1-12 and 1-13
Problems for practice
1-19

Reading for next class: sections 1-5 thru 1-7




9/15/09 - L2
Copyright 2009 - Joanne DeGroat, ECE, OSU
22