Transcript 2 - LIACS

Digital Techniques
Instructor: Dr. André Deutz
Office: Room 116
Office Phone: 071 - 527 – 7071
Email Address: [email protected]
Office Hours: Mondays 16:30-18:00
Digital Techniques





Lab Assistants
Gerben van der Lubbe (email:
[email protected] )
Drs. Dmitry Nadezhkin (email: [email protected];
phone: 071-527-5775)
Sjoerd Henstra (email: [email protected]), BSc in
Computer Science
Simon Zaaijer (email: [email protected] )
Fall 2007 Digital Techniques by André Deutz, Leiden University
2
Digital Techniques
Text Book:
M.Morris Mano and Charles R. Kime, Logic and
Computer Design Fundamentals, 4th Ed., 2008,
Pearson Education ; isbn-13: 978-0-13-198926-9;
isbn-10: 0-13-198926-X
Useful Link:
The URL of the Companion Website:
http://www.prenhall.com/mano
Tip: see also the errata
Fall 2007 Digital Techniques by André Deutz, Leiden University
3
Digital Techniques
References
Snyder, L., Fluency with Information Technology,
second edition, 2005, Addison-Wesley (third edition
due in October of 2007) (NB this textbook is not
required!)
The site of Great Principles of Computing:
http://cs.gmu.edu/cne/pjd/GP/
Fall 2007 Digital Techniques by André Deutz, Leiden University
4
Digital Techniques
Tentative Course Outline
Lecture
Date
Topic
1
2
3
4
5
Org; computer science; number systems;
Number systems; digital systems & information
Combinational logic circuits
Combinational logic design
Physical implementation
7
8
9
Sep 10
Sep 17
Sep 24
Oct 1
Wed 10 Oct
15.00 –
16.45
Oct 15
Oct 22
Oct 29
Nov 5
Nov 12
10
11
12
13
Nov 19
Nov 26
Dec 3
Dec 10
Memory
Processor design
Processor design
Processor design
6
Arithmetic functions and circuits
test
Sequential circuits; flip-flops and latches
Sequential circuits; flip-flops and latches; registers
Counters; memory
Reading
Assignments
Chapter 1
Chapter 1
Chapter 2
Chapter 3
Part of Chapter 6
Part of Chapter 4
Part of Chapter 5
Part of Chapter 5
Part of Chapter 5;
Part of Chapter 8
Part of Chapter 8
Chapter 9 & 10
Chapter 9 & 10
Chapter 9 & 10
Exam (tentamen): Test, Monday, 22 October; Friday, Jan. 11, 2008; retake 1,
Wednesday, Mar. 26, 2008; retake 2, Friday, Aug. 8, 2008
Fall 2007 Digital Techniques by André Deutz, Leiden University
5
Digital Techniques
Test: 14:00 – 17:00; Monday, October 22, 2007
Exam: 14:00-17:00; Friday, Jan. 11, 2008;
retake 1: 14:00-17:00; Wednesday, Mar. 26, 2008;
retake 2: 10:00-13:00; Friday, Aug. 8, 2008
6
Digital Techniques
Assignments
There are two kinds of assignments: 1) pencil-andpaper assignments and 2) processor-project
assignments.
7
Digital Techniques
Collaboration
The pencil-and-paper assignments are done individually. You
may work on the processor-project assignments in teams of
two. You may consult any source for design and
implementation ideas, as long as the synthesis and
implementation of these ideas is your own work. It goes
without saying that you need to credit any source you are
using in your work. The above remarks pertain to both kinds
of assignments. If in doubt on how to proceed in this matter,
consult the instructor of the course.
8
Digital Techniques
Deadlines
Please submit the assignments by the stated deadlines.
Pencil-and-paper are due 7 days after availability on the web
or by email . Therefore you are obliged to check your email
and/or web daily (as already stated above). The deadlines
for the processor-project assignments will be stated
separately. Deadlines are hard deadlines because the
answers to the assignments will be posted on the web shortly
after the deadline. It goes without saying that we will deal
appropriately with exceptionally harsh circumstances beyond
your control.
9
Digital Techniques
Grade
The grade for the course will be determined by considering the
grade for the exam (tentamen), the assignments, and the
practicum project. The weights for computing the course
grade are as follows:
Exam and Test:
50%
Pencil-and-Paper Assignments: 10%
Processor-Project Assignments : 40%
Moreover the grade for the Exam as well as the grade for the
Processor-Project Assignment should exceed 6..
10
Digital Techniques
Give a definition of the term Computer Science
(informatica).
11
Digital Techniques
Give a definition of the term Computer Science (informatica).
Possible answers:
To make the digital world (faster), more efficient, and above all more intelligent.
The study of phenomena with respect to (digital) computers.
The study of representation, analysis, transformation of information
van Dale: leer van de mechanische verzameling en verwerking van
informatie
Van Dale (paar jaar geleden): leer van het verzamelen en de verwerking van
gegevens m.b.v. computers
Computing is the study of information processes, natural and artificial.
12
Digital Techniques
Goal of the Course:
Our goal is to gain more insight into natural and manmade/artificial information processes with a focus on
man-made/artificial information processing. This
goal is, of course, too ambitious and encompasses
more than one (if not all) course(s) of our BSc in
Computer Science program. A slightly more modest
(and perhaps more feasible) goal is to learn to
understand information processing à la von
Neumann.
13
Digital Techniques
Objective
Build a simple computer based on the von Neumann
model of computation (which in the man-made world
is still the ubiquitous model of computation).
14
Digital Techniques
Description
In this course we will learn how to build a simple computer
based on the von Neumann model of computation.
To that end we need to study the following topics: Digital
Systems and Information, Number Systems, Binary
Arithmetic Operations, Decimal and Alphanumeric Codes,
Boolean Algebra, Combinational Logic Circuits, Logic
Functions and Circuits, Arithmetic Functions and Circuits,
Sequential Circuits, Memory Basics, Registers and Register
Transfers, Computer Design Basics.
As simulation tool we will use Digital Works 3.04.The key for
Digital Works: 8290-0018-0300-0087
15
Number Systems
Overview

Number Systems



Representations of Numbers in Digital Computers


Integer Numbers (unsigned and signed representations)
Arithmetic Operations



Positional Number Systems (decimal, binary, octal, and hexadecimal)
Number Conversions (r-to-decimal, decimal-to-r, other conversions)
General Remarks
Unsigned, Signed,
Decimal Codes


BCD code, Alphanumeric Codes
ASCII and Unicode
Fall 2007 Digital Techniques by André Deutz, Leiden University
17
Digital Systems: General Remarks


A Digital System manipulates discrete elements/quantities of
information
Discrete quantities of information emerge from:




Early computer systems were used mostly for numeric
computations: the discrete elements used were the digits,
hence the term digital computer/system emerged.
In general, any system uses an alphabet (set of symbols) to
represent information



the nature of the data being processed
the data may be purposely quantized from continues values
The English language system uses an alphabet of 26 symbols (letters)
The decimal number system uses an alphabet of 10 symbols (digits)
What about the alphabet of the Digital Systems?
Fall 2007 Digital Techniques by André Deutz, Leiden University
18
The Digital Systems’ Alphabet is Binary

Digital Systems use only one alphabet with two symbols
(digits) ‘0’ and ‘1’ (hence binary ).



A binary digit is called a bit
Information is represented by groups of bits
Why is a binary alphabet used?



Digital systems have a basic building block called a switch, that can
only be “on” or “off”, i.e., two discrete values ‘0’ and ‘1’ can be
distinguished.
An electric device, called a transistor, physically implements the
switch.
The two discrete values are physically represented by ranges of
voltage values called HIGH and LOW.



“on” (closed) switch corresponds to bit value ‘0’ and is represented by
LOW voltage value (between 0.0 and 1.0 Volt).
“off” (open) switch corresponds to bit value ‘1’ and is represented by
HIGH voltage value (between 4.0 and 5.0 Volts).
More information will be given later in another lecture.
Fall 2007 Digital Techniques by André Deutz, Leiden University
19
Information Representation

All information in Digital Systems is represented in binary
form.
An Aside:
Wine merchants in England (13th century or earlier)
2 gills = 1 chopin
2 chopins = 1 pint
2 pints = 1 quart
2 quarts = 1 pottle
2 pottles = 1 peck
2 pecks = 1 demibushel
2 demibushels = 1 bushel or firkin
2 firkins = 1 kilderkins
2 kilderkins = 1 barrel
2 barrels = 1 hogshead
2 hogshead = 1 pipe
2 pipes = 1 tun
Fall 2007 Digital Techniques by André Deutz, Leiden University
20
Information Representation



All information that is not binary is converted to
binary before processed by a Digital Systems.
Decimal numbers are expressed in the binary
number system or by means of a binary code.
How is this done?


That is not too difficult, once we understand how all
number systems, not only the decimal one (0-9), have a
similar formal representation and how a number in one
number system can be converted into another.
Let us look into number systems and conversions.
Fall 2007 Digital Techniques by André Deutz, Leiden University
21
Number Systems
Number Systems are employed in arithmetic to represent
numbers by strings of digits. There are two types of number
systems:
 Positional number systems


The meaning of each digit depends on its position in the number.
Example:



Decimal number system (we know it very well and use it in everyday
arithmetic).
585.5 is a decimal number in positional code – “5 hundreds plus 8 tens
plus 5 units plus 5 tenths”. The hundreds, tens, units, and tenths are
powers of 10 implied by the position of the digits.
Decimal number system is said to be of base or radix 10 because it uses
10 distinct digits (0 – 9) and the digits are multiplied by power of 10:
585.5 = 5x102 + 8x101 + 5x100 + 5x10-1

Non-positional number systems

Old Roman numbers: for example, XIX equals to 19
Fall 2007 Digital Techniques by André Deutz, Leiden University
22
Positional Number Systems
We can represent numbers in any number system with base r

Number in positional code

(An-1An-2…A1A0.A-1A-2…A-m+1A-m)r

r is the base (radix) of the system, r  {2, 3, …, I}.

every digit Ai  {0, 1, 2, …, r-1}, where {0, 1, 2, …, r-1} is the digit set.

“.” is called the radix point.



Number in base r expressed as power series of r


An-1 is referred to as the most significant digit.
A-m is referred to as the least significant digit.
An-1 r n-1 + An-2 r n-2 +…+ A1 r 1 + A0 r 0 + A-1 r -1 + A-2 r -2 +…+ A-m+1 r –m+1 + A-m r -m
Example: a number in number systems with base 5

(132.4)5 = 1x52 + 3x51 + 2x50 + 4x5-1 = 25 + 15 + 2 + 0.8 = (42.8)10
Fall 2007 Digital Techniques by André Deutz, Leiden University
23
Binary Number System
This is the system used for arithmetic in all digital computers

Number in positional code

(bn-1bn-2…b1b0.b-1b-2…b-m+1b-m)r

r = 2 is the base of the binary system.





Number in base 2 expressed as power series of 2


every digit bi  {0, 1}
the digits bi in a binary number are called bits
bn-1 is referred to as the most significant bit (MSB).
b-m is referred to as the least significant bit (LSB).
bn-1 2 n-1 + bn-2 2 n-2 +…+ b1 2 1 + b0 2 0 + b-1 2 -1 + b-2 2 -2 +…+ b-m+1 2 –m+1+ b-m 2 -m
Example: a number in the binary number system

(1011.01)2 = 1x23 + 0x22 + 1x21 + 1x20 + 0x2-1 + 1x2-2 = 8 + 2 + 1 + 0.25 =
(11.25)10
Fall 2007 Digital Techniques by André Deutz, Leiden University
24
Memorize this table by heart!!!!!!!!
Power of Two
n
n
n
n
2
n
2
1
5
32
10
1024
1
2
6
64
11
2048
2
4
7
128
12
4096
3
8
8
256
13
8192
4
16
9
512
14
16384
n
2
0
210  1,024 is 1K
(kilo)
2 20 is 1M
(mega)
2 30 is 1G
(giga)
Fall 2007 Digital Techniques by André Deutz, Leiden University
25
Other Useful Number System
Apart from the ordinary binary number system, the octal (base-8) and the
hexadecimal (base-16) number systems are useful for representing binary
quantities indirectly because their bases are powers of two. These systems
have a more compact representation of binary quantities.

Octal number system





(on-1on-2…o1o0.o-1o-2…o-m+1o-m)8
every digit oi  {0, 1, 2, 3, 4, 5, 6, 7}.
on-1 8 n-1 + on-2 8 n-2 +…+ o1 8 1 + o0 8 0 + o-1 8 -1 + o-2 8 -2 +…+ o-m+1 8 –m+1 +o-m 8 -m
(127.4)8 = 1x82 + 2x81 + 7x80 + 4x8-1 = (87.5)10 = (001 010 111.100)2
Hexadecimal number system




(hn-1hn-2…h1h0.h-1h-2…h-m+1h-m)16
every digit hi  {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F}.
hn-1 16 n-1 + hn-2 16 n-2 +…+ h1 16 1 + h0 16 0 + h-1 16 -1 + h-2 16 -2 +…+ h-m+1 16 –m+1
+ h-m 16 –m
(B6F.4)16 = 11x162 + 6x161 + 15x160 + 4x16-1 = (2927.25)10 = (1011 0110
1111.0100)2
Fall 2007 Digital Techniques by André Deutz, Leiden University
26
Another Important Table
Decimal (base 10)
Binary (base 2)
Octal (base 8)
Hex (base 16)
0
0000
00
0
1
0001
01
1
2
0010
02
2
3
0011
03
3
4
0100
04
4
5
0101
05
5
6
0110
06
6
7
0111
07
7
8
1000
10
8
9
1001
11
9
10
1010
12
A
11
1011
13
B
12
1100
14
C
13
1101
15
D
14
1110
16
E
15
1111
17
F
Fall 2007 Digital Techniques by André Deutz, Leiden University
27
Conversion from base r to Decimal
The conversion of a number in base r to decimal number (base 10) is done
by expanding the number in power series and adding all the terms as shown
below:
(An-1An-2…A1A0.A-1A-2…A-m+1A-m)r =
An-1 r n-1 + An-2 r n-2 +…+ A1 r 1 + A0 r 0 + A-1 r -1 + A-2 r -2 +…+ A-m+1 r –m+1 + A-m r -m

Example of converting Binary (base 2) to Decimal (base 10):
(1011.01)2 = 1x23 + 0x22 + 1x21 + 1x20 + 0x2-1 + 1x2-2 = 8 + 2 + 1 + 0.25 = (11.25)10

Example of converting number in base 5 to Decimal (base 10):
(132.4)5 = 1x52 + 3x51 + 2x50 + 4x5-1 = 25 + 15 + 2 + 0.8 = (42.8)10
Example of converting Octal (base 8) to Decimal (base 10):
(127.4)8 = 1x82 + 2x81 + 7x80 + 4x8-1 = (87.5)10

Example of converting Hexadecimal (base 16) to Decimal (base 10):
(B6F.4)16 = 11x162 + 6x161 + 15x160 + 4x16-1 = (2927.25)10

Fall 2007 Digital Techniques by André Deutz, Leiden University
28
Conversion from Decimal to base r
The conversion is done as follows:
1) If the number has a radix point then separate the number into an integer
part and a fraction part, since the two parts must be converted differently.
2) The conversion of a decimal integer part to a number in base r is done by
dividing the integer part and all successive quotients by r and
accumulating the remainders.
3) The conversion of a decimal fraction part to a number in base r is done by
multiplying the fractional parts by r and accumulating integers.

Example of converting Decimal (base 10) to Binary (base 2): (41.6875)10
Converting the integer part (41)10 :
Converting the fraction part (0.6875)10 :
41/2 = 20 + 1/2
20/2 = 10 + 0/2
10/2 = 5 + 0/2
5/2 = 2 + 1/2
2/2 = 1 + 0/2
1/2 = 0 + 1/2
0.6875 x 2 = 1.3750 Integer = 1
0.3750 x 2 = 0.7500
0
0.7500 x 2 = 1.5000
1
0.5000 x 2 = 1.0000
1
(0.6875)10 = (0.1011)2
Remainder = 1
0
0
1
0
1
(41)10 = (101001)2
LSB
MSB
LSB
MSB
(41.6875)10 = (101001.1011)2
Fall 2007 Digital Techniques by André Deutz, Leiden University
29
Other Conversions


Binary to Octal or Hexadecimal: grouping bits starting from the radix point
 (1101010.01)2 to Octal (groups of 3): (001|101|010.010|)2 = (152.2)8
 (1101010.01)2 to Hex (groups of 4): (0110|1010.0100|)2 = (6A.4)16
Octal to Binary: convert each digit to binary using 3 bits


Hexadecimal to Binary: convert each digit to binary using 4 bits


(7A5F.C)16 = (0111 1010 0101 1111. 1100)2 = (111101001011111.11)2
Hexadecimal to Octal


(475.2)8 = (100 111 101. 010)2
Hexadecimal  Binary  Octal
Octal to Hexadecimal

Octal  Binary Hexadecimal
Fall 2007 Digital Techniques by André Deutz, Leiden University
30
Number Ranges






The range of numbers in base (radix) r depends on the number of digits
used to represent the numbers.
Assume the number (An-1An-2…A1A0.A-1A-2…A-m+1A-m)r represented by n
digits for the integer part and m digits for the fraction part.
The smallest integer number is 0 and the largest is (r-1) r n-1 + (r-1) r n-2 +
…+ (r-1)r 1 + (r-1) r 0 = rn-1 ,i.e., the range is from 0 to rn-1
The smallest fraction number is 0.0 and the largest is (r-1) r -1 + (r-1) r -2 +
…+ (r-1) r –m+1 + (r-1) r –m = 1- r –m ,i.e., the range is from 0.0 to 1- r –m
The range of numbers is from 0.0 to rn - r –m
Examples:





Largest 3-digit integer decimal (base 10) number is 103-1 = 1000 - 1 = 999
Largest 8-digit integer binary (base 2) number is (11111111)2 ,i.e., 28-1 = 255
Largest 5-digit decimal (base 10) fraction is 1-10-5 = 1 – 0.00001 = 0.99999
Largest 16-digit binary (base 2) fraction is 1-2-16 = 0.9999847412
What about the range of negative numbers?
Fall 2007 Digital Techniques by André Deutz, Leiden University
31
Representations of Numbers in Digital
Computers (1)

Numbers are represented in binary format as strings of bits





Bit is the smallest binary quantity with a value of 0 or 1.
Byte is a string (sequence) of eight bits.
Word is a string (sequence) of n bits (n > 8). In most cases n is a
power of 2 (n = 24 = 16, n = 25 = 32, n = 26 = 64, etc…).
Examples  bit: 1 byte: 01101111 16-bit word: 11110100 10001010
Positive Integer Numbers


Positive integers and the number zero can be represented as
unsigned binary numbers using a byte or an n-bit word.
Magnitude representation – number N in binary having n bits.


Radix complement ( r’s complement ) representation in our case 2’s
complement – Given number N in binary having n bits, the 2’s
complement of N is defined as 2n – N .


Example: 00001001 ( represents integer number 9 using 8 bits ).
Example: 11110111 ( 2’s complement of integer number 9 ).
Diminished radix complement ( (r-1)’s complement ) representation in
our case 1’s complement - Given number N in binary having n bits,
the 1’s complement of N is defined as (2n – 1) – N .

Example: 11110110 ( 1’s complement of integer number 9 ).
Fall 2007 Digital Techniques by André Deutz, Leiden University
32
Representations of Numbers in Digital
Computers (2)

Positive and Negative Integer Numbers


Positive and negative integers and the number zero can be
represented as signed binary numbers using a byte or an n-bit word
where the most significant bit is interpreted as a sign bit. The
convention is to make the sign bit 0 for positive numbers and 1 for
negative numbers.
Signed-Magnitude representation



Signed-Radix complement ( signed-r’s complement ) representation in
our case signed-2’s complement (n=8 in the example below)



Example: 0|0001001 ( represents integer number +9 using 8 bits ).
Example: 1|0001001 ( represents integer number -9 using 8 bits ).
Example: 0|0001001 ( signed-2’s complement of integer number +9 ).
Example: 1|1110111 ( signed-2’s complement of integer number -9 ).
How do we get the signed complement?
Fall 2007 Digital Techniques by André Deutz, Leiden University
33
Arithmetic Operations

Arithmetic operations with numbers in base r follow the same
rules as for decimal numbers.

Examples: addition, subtraction, and multiplication in base-2.
Carries: 111
Augend: 10110
+
Addend: 01110
Sum: 100100



Borrows:
Minuend: 00110
Subtrahend: 11101
Difference:
11
- 11101
00110
-10111
Multiplicand: 1010
x
Multiplier:
101
1010
+ 0000
1010
Product: 110010
For more information study pages 18-20 in the text book.
In Digital Computers arithmetic operations are done with the
binary number system (base-2) - Binary Arithmetic.
In many cases binary subtraction is done in a special way by
binary addition. Why?


It is much more simple to do it that way.
One simple building block called adder can be implemented and used
for both binary addition and subtraction.
Fall 2007 Digital Techniques by André Deutz, Leiden University
34
Unsigned Binary Subtraction

Binary subtraction by 2’s complement addition




Assume two n-bit unsigned numbers M and N, M - N can be done as follows:
Add the 2’s complement of N to M. This performs the sum M + (2n - N) =
= M – N + 2n .
If M ≥ N, the sum produces an end carry, 2n. We can discard it, leaving the
correct result M – N.
If M < N, the sum does not produces an end carry since it is equal to
2n – (N - M), which is the 2’s complement of N – M. To obtain the correct
result take the 2’s complement of the sum, i.e., 2n – (2n – (N - M)) = (N - M)
and place a minus sign in front.
Examples:
15
1111 (15)
+
5
1011 (2’s compl. of 5)
10 1 1010 (the sum)

discard carry
-
5
15
-10
no carry
+
0101 (5)
0001 (2’s compl. of 15)
0110 (the sum)
correction is needed
-1010 ( “-” 2’s compl. of sum )

What about binary subtraction by 1’s complement addition?

I leave this for you as a home work
Fall 2007 Digital Techniques by André Deutz, Leiden University
35
Signed Binary Addition/Subtraction

Signed binary addition using 2’s complement representation



Assume two n-bit signed numbers M and N represented in signed-2’s
complement format. The sum M + N can be obtained as follows:
Add M to N, including their sign bits to get the correct sum in signed-2’s
complement format. A carry out of the sign bit position is discarded.
Examples:
(- 9)
+ (+ 5)
(- 4)
1|0111
0|0101
1|1100
(- 9) 1|0111
+ (- 5) 1|1011
(-14) 11|0010
(+ 9)
+ (+ 5)
(+14)
0|1001
0|0101
0|1110
(+ 9) 0|1001
+ (- 5) 1|1011
(+ 4) 10|0100
discard

Signed binary subtraction using 2’s complement representation



discard
Assume two n-bit signed numbers M and N represented in signed-2’s
complement format. The difference M - N can be obtained as follows:
Take the 2’s complement of N (including the sign bit) and add it to M
(including the sign bit). A carry out of the sign bit position is discarded.
Examples:
(- 9)
- (- 5)
(- 4)
1|0111
1|1011
+
1|0111
0|0101
1|1100
(- 9)
- (+ 5)
(-14)
1|0111
0|0101
1|0111
1|1011
11|0010
+
Fall 2007 Digital Techniques by André Deutz, Leiden University
discard
36
Decimal Codes


The binary number system is the most natural system for a
digital computer, but people are accustomed to the decimal
system.
How to resolve this difference?



Convert decimal numbers to binary, perform all arithmetic
calculations in binary, and then convert the binary result back to
decimal.
You already know how to do this.
Digital computers can do this as well, but:


We have to store the decimal numbers in the computer in a way that
they can be converted to binary.
Since the computer can accept only binary values, we must represent
the decimal digits by a code that contains 1’s and 0’s.
Fall 2007 Digital Techniques by André Deutz, Leiden University
37
Binary Coded Decimals (BCD)



The BCD code is the most commonly used code.
Each decimal digit (0, 1, 2, …, 9) is coded by a
4-bit string (half a byte) called BCD digit.
A decimal number is converted to a BCD
number by replacing each decimal digit of the
number with the corresponding BCD digit code.
Example:
(369)10 = ( 0011 0110 1001 )BCD = (101110001)2
3
6
9

A BCD number needs more bits than its
equivalent binary value. However, the
advantages of using BCD are:



Computer input and output data are handled by
people who use the decimal system.
BCD numbers are decimal numbers (not binary
numbers) even though they are represented in
bits.
Computers can store decimal numbers using BCD,
convert the BCD numbers to binary, perform binary
operations, and convert the result back to BCD.
(1)
Decimal Digit
BCD Digit
0
0000
1
0001
2
0010
3
0011
4
0100
5
0101
6
0110
7
0111
8
1000
9
1001
Note: the binary
combinations 1010
through 1111 are not
used and have no
meaning in the BCD
code.
Fall 2007 Digital Techniques by André Deutz, Leiden University
38
Binary Coded Decimals (BCD)

(2)
Converting a BCD number to a binary number
(25)10 = (0010 0101)BCD = (0010)2 x 101 + (0101)2 x 100 =
= (0010)2 x (1010)2 + (0101)2 x (0001)2 =
= (10100)+(0101) = (11001)2

Converting a binary number to a BCD number
Convert the number (11001)2 by dividing it to (1010)2 = (10)10
(11001)2 / (1010)2 = (0010)2 and Remainder = (0101)2
(0010)2 / (1010)2 = (0000)2 and Remainder = (0010)2
Least significant BCD digit
Most significant BCD digit
(11001)2 = ( 0010 0101 )BCD = (25)10

BCD Arithmetic

Digital computers can performed arithmetic operations directly with
decimal numbers when they are stored in BDC format.

How is this done? (study the text book or go to internet for information).
Fall 2007 Digital Techniques by André Deutz, Leiden University
39
Other Useful Decimal Codes:
Seven-Segment Code


Used to display numeric info on seven-segment displays.
Seven-segment display:



7 LEDs (light emitting diodes), each one controlled by an input
1 means “on”, 0 means “off”
Decimal Digit
7- Segment Code
Display digit “3”?


Set a, b, c, d, g to 1
Set e, f to 0
f
a
b
g
e
c
d
a
b
c
d
e
f
0
1
1
1
1
1
1 0
1
0
1
1
0
0
0 0
2
1
1
0
1
1
0 1
3
1
1
1
1
0
0 1
4
0
1
1
0
0
1 1
5
1
0
1
1
0
1 1
6
1
0
1
1
1
1 1
7
1
1
1
0
0
0 0
8
1
1
1
1
1
1 1
9
1
1
1
1
0
1 1
Fall 2007 Digital Techniques by André Deutz, Leiden University
g
40
Alphanumeric Codes

Many applications of digital computers require the handling
of data consisting not only of numbers, but also of letters.

Alphanumeric character set of English includes:




We need to code these symbols



The code must be binary – computers can handle only 0’s and 1’s
We need binary code of at least seven bits (27 = 128 symbols)
American Standard Code for Information Interchange (ASCII)


The 10 decimal digits
The 26 letters of the alphabet (uppercase and lowercase letters)
Several (more than three) special characters
ASCII is a 7-bit standard code for representing the symbols of the
English language.
Unicode

A 16-bit standard code for representing the symbols and ideographs
for the world’s languages.
Fall 2007 Digital Techniques by André Deutz, Leiden University
41
ASCII Code Table
Fall 2007 Digital Techniques by André Deutz, Leiden University
42
ASCII Character Code
• ASCII is a 7-bit code,
commonly stored in 8bit bytes.
• “A” is at 4116. To
convert upper case
letters to lower case
letters, add 2016. Thus
“a” is at 4116 + 2016 =
6116.
• The character “5” at
position 3516 is
different than the
number 5. To convert
character-numbers
into number-numbers,
subtract 3016: 3516 3016 = 5.
Fall 2007 Digital Techniques by André Deutz, Leiden University
43
ASCII Code Table
Fall 2007 Digital Techniques by André Deutz, Leiden University
44
Gray Codes
Fall 2007 Digital Techniques by André Deutz, Leiden University
45
What is What?
How do you know whether binary bit string 00110001
represents an ASCII code with odd parity for the
character ‘1’ , the positive number 49, or the positive
number 31?
46