Sei sulla pagina 1di 28

CS 221

LOGIC DESIGN
Fall 2014
1

By Wessam El-Behaidy
Assistant Professor ,
Computer Science Department

CS221 _Lec2_ Dr.Wessam El-Behaidy_2014

REMEMBER OUR RULES

BINARY CODES
3

Lecture 2

CS221 _Lec2_ Dr.Wessam El-Behaidy_2014

BINARY CODES

Digital systems:
Use signals that have 2 distinct values and circuit
elements that have 2 stable states
Represent and manipulate not only binary numbers
but also many other discrete elements of information

Section 1.7

Any discrete element of information that is


distinct among group of quantities can be
represented with a binary code.
However, it must be realized that binary codes
merely change the symbols not the meaning of
the elements of information that they represent.

Decimal
Symbol
BCD
Digit

0000 0001 0010 0011 0100 0101 0110 0111 1000 1001

Note: 1010, 1011, 1100, 1101, 1110, and 1111 are INVALID CODE!

Section 1.7

It is important to realize that BCD numbers are


decimal numbers and not binary numbers. The only
difference that decimals use symbols 0-9 and BCD
use 000-1001
A number with k decimal digits will require 4k bits in
BCD
5
Ex: (185)10= (0001 1000 0101)BCD =(1011 1001)2

CS221 _Lec2_ Dr.Wessam El-Behaidy_2014

BINARY-CODED DECIMAL (BCD)

CS221 _Lec2_ Dr.Wessam El-Behaidy_2014

BCD ADDITION
Example:

4
+5
9

0100
+1000
1100
+0110
10010

4
+8
12

0100
+0101
1001

> 9 (1001)

BCD
Digit

>9

1000
+ 1001
10001
+0110
10111
1

0000 0001 0010 0011 0100 0101 0110 0111 1000 1001

Section 1.7

Decimal
Symbol

8
+9
17

CS221 _Lec2_ Dr.Wessam El-Behaidy_2014

BCD ADDITION (CONT.)


Example:

BCD

0001 1000 0100


+0101 0111 0110
0111 10000
0110
0111 0110

1010
0110
0000

>9

760
7

Section 1.7

Binary sum
Add 6
BCD sum

184
+576

CS221 _Lec2_ Dr.Wessam El-Behaidy_2014

OTHER DECIMAL CODES

Section 1.7

Binary codes
for decimal
digits require
a minimum of
4 bits per digit
Many
different
codes can be
formulated by
arranging 4
bits into 10
distinct
combinations

CS221 _Lec2_ Dr.Wessam El-Behaidy_2014

WEIGHTED CODES
BCD

, 2421 code and 8,4,-2,-1 code are examples of


weighted codes.
In weighted code, each bit position is assigned a
weighted factor

Ex:

Section 1.7

0110BCD =610
because 8*0 + 4*1 + 2*1+ 1*0 = 6
11012421 =710
because 2*1 + 4*1 + 2*0 + 1*1 =7
01108,4,-2,-1=210
because 8*0 + 4*1 + (-2)*1 + (-1)*0 =2

CS221 _Lec2_ Dr.Wessam El-Behaidy_2014

SELF-COMPLEMENTING CODES
The

10

Section 1.7

2421 and excess-3 codes are examples of selfcomplementing codes.


Such codes have the property that 9s complement of a
decimal number is obtained directly by changing 1s to
0s and 0s to 1s.
Example:
9s complement (395) = 604
Excess-3(395)= 0110 1100 1000
Excess-3(604)= 1001 0011 0111

CS221 _Lec2_ Dr.Wessam El-Behaidy_2014

THE GRAY CODE


The

Gray code is unweighted and is not


an arithmetic code.

There are no specific weights assigned to the


bit positions.

Important:

the Gray code exhibits only a


single bit change from one code word to
the next in sequence.
This property is important in many
applications
11

Section 1.7

CS221 _Lec2_ Dr.Wessam El-Behaidy_2014

ALPHANUMERIC CODES

Represent numbers and alphabetic characters.

Also represent other characters such as symbols and


various instructions necessary for conveying
information.

The ASCII is the most common alphanumeric


code.

ASCII = American Standard Code for Information


Interchange

Section 1.7

12

ASCII has 128 characters and symbols


represented by a 7-bit binary code.

ASCII(A)= 1000001
Column 100, row 0001

Section 1.7

13

CS221 _Lec2_ Dr.Wessam El-Behaidy_2014

ASCII CODE

CS221 _Lec2_ Dr.Wessam El-Behaidy_2014

ASCII CODE (CONT.)


It contains:
94 graphic characters that can be printed:

(A-Z), (a-z),(0-9),and 32 special characters (%,*,$,)

34 non-printed characters used for various


control functions.

Format effectors: control the layout of printing

Information separators: separate the data into


divisions such as paragraphs and pages
Record separator (RS) and file separator (FS)

Communication-control characters: useful during


transmission of text between remote terminals.

Start text (STX), End of text(ETX)

14

Section 1.7

Backspace (BS), horizontal tabulation (HT) and carriage


return (CR)

CS221 _Lec2_ Dr.Wessam El-Behaidy_2014

ASCII CODE (CONT.)


ASCII characters most often are stored one per
byte.
The extra bit is sometimes used for other
purposes, depending on the application.
Example:

15

Section 1.7

Some printers recognize eight-bit ASCII characters


with the most significant bit set to 0.
An additional 128 eight-bit characters with the most
significant bit set to1 are used for other symbols such
as the Greek alphabet or italic type font.

CS221 _Lec2_ Dr.Wessam El-Behaidy_2014

ERROR-DETECTING CODE
To detect errors in data communication and
processing, an 8th bit is sometimes added to
ASCII character to indicate its parity.
A parity bit is an extra bit included with a
message to make the total number of 1s either
even or odd.

with odd parity


11000001
01010100
16

Section 1.7

ASCII A=1000001
ASCII T=1010100

with even parity


01000001
11010100

CS221 _Lec2_ Dr.Wessam El-Behaidy_2014

EVEN PARITY
It is the most used.
At the sender:

An even parity bit is generated for each character


The 8-bit characters are transmitted to the receiver

At the receiver:
The parity of each character is checked
If the parity of the received character is not even,
then at least one bit has changed during
transmission

17

Section 1.7

It detects any odd combination of errors


An even combination of errors goes undetected
and additional error detection codes may be
needed.

CS221 _Lec2_ Dr.Wessam El-Behaidy_2014

EVEN PARITY (CONT.)

If the receiver detects a parity error,


It sends back to sender ASCII NAK (negative
acknowledge) control character consisting of an even
parity 8-bits (10010101)
Then, the sender respond to NAK by transmitting the
message again until the correct parity is received

If no error is detected,

the receiver sends back an ACK (acknowledge)


control character (00000110)

Section 1.7

18

CS221 _Lec2_ Dr.Wessam El-Behaidy_2014

REGISTER
The binary information must have a physical
existence in some medium for storing individual
bits.
A binary cell

Is a device that possesses two stable states and is


capable of storing one bit (0 or 1) of information

A register

Is a group of binary cells.


0

n-1

.
19

A binary cell stores 0 or 1

Section 1.8

A register with
n bits with
n binary cells

CS221 _Lec2_ Dr.Wessam El-Behaidy_2014

REGISTER TRANSFER EXAMPLE

Section 1.8

20

CS221 _Lec2_ Dr.Wessam El-Behaidy_2014

Before we proceed,
Any questions?

CS221 _Lec2_ Dr.Wessam El-Behaidy_2014

BINARY LOGIC
Binary

values.

variables take on one of two

We use 1 and 0 to denote the two values.

Examples:

The

z = x . y or

z=xy z is equal to x AND y

OR

Ex:

Ex:

NOT

Ex:

Section 1.9

three basic logical operations are:

AND

A, B, y, z, or X1

z = x + y z is equal to x OR y
z=x

or

z=x z is equal to NOT x

22

CS221 _Lec2_ Dr.Wessam El-Behaidy_2014

TRUTH TABLE
It is a table of all possible combinations of the
variables
It shows the relation between

The values that the variables may take and


The result of the operation

Section 1.9

23

CS221 _Lec2_ Dr.Wessam El-Behaidy_2014

TIMING DIAGRAM

Timing diagram

Section 1.9

Figure 1.5

24

CS221 _Lec2_ Dr.Wessam El-Behaidy_2014

LOGIC GATES SYMBOLS

Figure 1.4

Gates with multiple inputs:

Section 1.9

Figure 1.6

When F=1? and when G=1?

25

CS221 _Lec2_ Dr.Wessam El-Behaidy_2014

LOGIC GATES
OTHER

=xy

=xy

Section 2.8

26

CS221 _Lec2_ Dr.Wessam El-Behaidy_2014

EXAMPLE

Draw a logic gate circuit of A +B and get their


truth table

Z= A +B

0
0
1
1

0
1
0
1

1
1
0
0

1
1
0
1

27

THANKS
28

We covered:

Ch.1 (sec. 1.7 - sec. 1.9)

Try to solve: 1.22, 1.23, 1.25, 1.28 -1.30, 1.32-1.36

Potrebbero piacerti anche