LAB #0: Review of Digital Logic Concepts

advertisement
LAB #0: Review of Digital Logic Concepts
1.1 - Objectives:
The purpose of this lab is to review basic digital logic concepts you have learned in previous digital
systems courses. When you complete this lab, you should be able to recall:




Number systems and conversions
Binary arithmetic and binary negative number representations
Binary coded decimal (BCD)
ASCII Standard
1.2 – Related material to read:
Roth, Charles. Fundamentals of Logic Design.
1.3 – Number systems and conversions
Base 10 (Decimal): The most familiar number system humans use is base 10. Each digit, ranging
from 0-9, in a decimal number is multiplied by the corresponding power of 10 depending on the
position in the number (this is known as positional notation).
150.510 = 1 x 102 + 5 x 101 + 0 x 100 + 5 x 10-1
Base 2 (Binary): Digital systems on the other hand make use of a base 2 (or binary) number system.
The same idea applies as with decimal numbers, in that each binary digit is multiplied by the
corresponding power of 2 depending on the position in the number.
1011.112 = 1 x 23 + 0 x 22 + 1 x 21 + 1 x 20 + 1 x 2-1 + 1 x 2-2
Base conversion (integer): To convert an integer value between two different bases, simply use
successive division. For example, to convert 5310 to binary, simply repeat integer division by the
conversion base until the quotient is zero.
53
= 26, 𝑅 = 1 = 𝑎0
2
26
= 13, 𝑅 = 0 = 𝑎1
2
13
= 6, 𝑅 = 1 = 𝑎2
2
6
= 3, 𝑅 = 0 = 𝑎3
2
3
= 1, 𝑅 = 1 = 𝑎4
2
1
= 0, 𝑅 = 1 = 𝑎5
2
5310 = 1101012
Base conversion (fraction): Fraction conversion can be done with successive multiplication. This
process is continued until a sufficient number of digits have been obtained. Note that this process may
not always terminate, in which case you will have a repeating fraction. For example, to convert 0.62510
to binary:
0.625 x 2 = 1.250 = 0.250 + 1 (a-1 = 1)
0.250 x 2 = 0.500 = .500 + 0 (a-2 = 0)
0.500 x 2 = 1.000 = .000 + 1 (a-3 = 1)
It is important to note that these processes can be used to convert from any generic base R 1 to a
different generic base R2; however, it is often easier and commonplace to convert generic base R1 to
base 10 (decimal) before converting to base R2.
Base 16 (Hexadecimal): For bases greater than 10, more symbols are required to represent the
digits. Base 16 (hexadecimal) makes use of digits 0-9 and letters A-F to represent values 10-15
respectively. For example,
A2F16 = 10 x 162 + 2 x 161 + 15 x 160 = 2607
Hexadecimal notation is a common base used to represent numbers in digital systems because
conversion from binary to hexadecimal (and conversely) can be simply done by inspection since each
hexadecimal digit corresponds to exactly four binary digits (bits). To convert a binary number to
hexadecimal, simply divide the bits into groups of four, where each group will correspond to a
hexadecimal digit. For example,
100111110.0100112 = 00012 00112 11102 . 01002 11002 -> 13E.4C16
1.4 – Binary Arithmetic
Arithmetic operations in digital systems are usually done in binary because digital logic circuit design
for binary is much simpler and faster than for decimal.
Binary subtraction table
0
0
1
1
-
Binary addition table
0 = 0
0 + 0 =
1 = 1*
0 + 1 =
0 = 1
1 + 0 =
1 = 0
1 + 1 =
*Carry/Borrow to/from next column
0
1
1
0*
For example, to add 1010 and 1510 in binary:
1010 + 1510 = 10102 + 11112 = 110012
To subtract 1010 from 1510 in binary:
1510 – 1010 = 11112 – 10102 = 01012
1.5 – Representation of negative numbers (2’s complement)
The 2’s complement of a binary number is defined as the value obtained by subtracting the number
from a large power of two (specifically, from 2N for an N-bit 2’s complement). The 2’s complement of
the number then behaves like the negative of the original number in most arithmetic, and it can coexist
with positive number in a natural way. A 2’s complement negative number binary representation can
be found for an n-bit number by applying the following simple equation:
N*=2n - N
For example, to represent -3 as a 4-bit 2’s complement number, one can apply the above equation or
simply take the positive binary representation, complement the bits, and add 1.
-3 = 24 – 1 = 16 – 3 = 13 = 11012
3 = 00112 – 3 = 11002 + 12 = 11012
1.5 – Arithmetic overflow
Since n-bit binary numbers are of fixed length, there are only a fixed set of numbers that can be
represented; therefore, it is possible to perform arithmetic on two n-bit binary numbers and get a
condition known as overflow. An overflow occurs when an arithmetic operation of two words of length
n-bits sum to a result that requires more than n-bits to correctly represent. This is true for both
unsigned and signed binary numbers.
For example, adding the following two 4-bit unsigned numbers will result in an overflow:
8 + 8 = 16  10002 + 10002 = 1 00002 = 0 ≠ 16
For example, adding the following two 4-bit signed numbers will result in an overflow:
-8 + -8 = -16 10002 + 10002 = 1 00002 = 0 ≠ -16
There are few simple statements to remember for 2’s complement numbers in order to know if an
overflow has occurred for a signed number:
1) If adding two negative signed numbers results in a positive number, an overflow has occurred.
2) If adding two positive signed numbers results in a negative number, an overflow has occurred.
3) For two n-bit signed numbers, it is impossible to get and overflow when adding a positive
number and a negative number, or subtracting a positive number from another positive
number.
4) If subtracting two numbers, take 2’s complement of the subtrahend (number being subtracted)
and perform addition using rules 1) – 3) above.
1.6 – Binary codes
Binary Coded Decimal (BCD): Although most computers work explicitly with binary numbers and
perform binary arithmetic operations, it is common to have input-output peripherials use decimal
numbers. This is often accomplished by representing decimal numbers in terms of binary codes. For
example, 524.8710 is represented as a binary coded decimal (BCD) by:
524.8710  01012 00102 01002 . 10002 01112
1.7 – American Standard Code for Information Interchange (ASCII)
It is common in most computing systems to require processing of data that contains information other
than numbers (e.g. letters, punctuation, symbols, etc…). One common alpha-numeric code is known
as ASCII. ASCII contains 7-bit binary codes, representing up to 27 = 128 different code combinations
for numbers, letters, and other symbols. For example, the digits 0 to 9 are represented by the values
$30 to $39 respectively. An ASCII table containing the code combinations can be found on the course
website (in “Lab Assignments” Appendix C).
1.8 – Lab report
Please print the last four pages of this lab, answer the questions, and turn in to your TA for credit. It is
suggested you use a calculator to verify your answer; however, you must show your work to get full
credit, otherwise you will receive a mark of zero for question.
Name:
Lab time:
LAB 1 Questions.
Number systems and conversions
1) Perform the following number conversions. Show your work.
a. 123410 to binary.
b. 56742 to binary.
c. 1011.1012 to decimal.
d. A4C3E89016 to decimal.
e. A4C3E89016 to binary.
f. 101.2510 to binary.
g. 72310 to octal (base 8).
h. 1324 to quinary (base 5).
2) Write out the following numbers in positional notation.
a. 168.1510
b. ABCD.EF16
c. 101102
3) A computer has a word length of 16-bits (including sign bit). What range of values can be
represented in the following cases (show your answers in binary and decimal):
a. 16-bit unsigned numbers
b. 16-bit 2’s complement signed numbers
c. 16-bit 1’s complement signed numbers
4) Write a formula for the range of values that can be represented by any n-bit binary
representation for the following cases:
a. n-bit unsigned numbers
b. n-bit 2’s complement signed numbers
Binary arithmetic and arithmetic overflow
1) Perform the following arithmetic operations and state whether and overflow has occurred. Also
show the result in decimal notation. All signed numbers are 2’s complement representations.
Show your work.
a. 10112 + 01102 (4-bit unsigned)
b. 10112 – 01102 (4-bit unsigned)
c. 10112 + 01102 (4-bit signed)
d. 10112 – 01102 (4-bit signed)
e. AF16 + 3C16 (8-bit unsigned)
f. AF16 - 3C16 (8-bit unsigned)
Binary codes
1) Perform the following binary code conversions. For ASCII conversion, convert the content
enclosed within the quotations marks (e.g. if asked to convert “ABC” Binary Coded
(Hexadecimal), then the result would be 4116 4216 4316).
a. 8214510 Binary coded decimal (BCD).
b. A43CD16 Binary coded decimal (BCD).
c. “ECE251” ASCII (Hexadecimal and Decimal notations).
d. Write your first name in ASCII codes (Hexadecimal and Decimal notations).
e. Write a formula to convert and ASCII digit (0-9 to its equivalent decimal representation.
f. Other than the ASCII standard, list another alpha-numeric standard commonly used.
g. Can the following symbols be represented in ASCII?
i. ©
Yes / No
ii. *
Yes / No
iii. R
Yes / No
iv. ±
Yes / No
v. =
Yes / No
Download