cs151 introduction to digital design chapter 1: digital systems and information lecture 4 1created...

23
CS151 Introduction to Digital Design Chapter 1: Digital Systems and Information Lecture 4 1 Created by: Ms.Amany AlSaleh

Upload: melissa-harmon

Post on 31-Dec-2015

219 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: CS151 Introduction to Digital Design Chapter 1: Digital Systems and Information Lecture 4 1Created by: Ms.Amany AlSaleh

CS151Introduction to Digital Design

Chapter 1: Digital Systems and Information

Lecture 4

1Created by: Ms.Amany AlSaleh

Page 2: CS151 Introduction to Digital Design Chapter 1: Digital Systems and Information Lecture 4 1Created by: Ms.Amany AlSaleh

2

Decimal Codes

Digital systems manipulate not only binary numbers, but also many other discrete elements of information.

Discrete elements can be represented by binary codes.

For n-bit binary code, we have 2n distinct combinations of 1’s and 0’s, with each combination representing one element of the set that is being coded. Each element can be assigned a unique binary bit combination.

Created by: Ms.Amany AlSaleh

Page 3: CS151 Introduction to Digital Design Chapter 1: Digital Systems and Information Lecture 4 1Created by: Ms.Amany AlSaleh

3

Decimal Codes (Cont.)

Examples: • How many elements can be coded using a 2-bit binary

code? Give the different combinations.

• A set of 4 elements.

• The different combinations are: 00,01,10 and 11.

• How many bits of code does a set of 8 elements require?

• 3-bit code (000, 001, 010, 011, 100, 101, 110, 111)

• How many bits of code does a set of 16 elements require?

• 4-bit code (0000, 0001, 0010, …, 1111)

The bit combinations of an n-bit code can be determined from the count in binary from 0 to 2n -1

Created by: Ms.Amany AlSaleh

Page 4: CS151 Introduction to Digital Design Chapter 1: Digital Systems and Information Lecture 4 1Created by: Ms.Amany AlSaleh

4

Decimal Codes (Cont.)

What if the number of elements in the set is not a power of 2?

Example: • How many bits of code does a set of 10 elements require?

• 4 bits. However 6 out of the 16 possible combinations will be unused.

Created by: Ms.Amany AlSaleh

Page 5: CS151 Introduction to Digital Design Chapter 1: Digital Systems and Information Lecture 4 1Created by: Ms.Amany AlSaleh

5

Binary Coded Decimal (BCD)

Each decimal digit is represented by 4 bits.

A number with n decimal digits requires 4n4n bits in BCD

Example: (396)10 =

(0011 1001 0110)BCD

A decimal number in BCD is the same as its equivalent binary number only when the number is between 0 and 9.

The binary combinations 1010 through 1111 are not used and have no meaning in BCD.

Digit BCD Code

Digit BCD Code

0 0000 5 0101

1 0001 6 0110

2 0010 7 0111

3 0011 8 1000

4 0100 9 1001

Created by: Ms.Amany AlSaleh

Page 6: CS151 Introduction to Digital Design Chapter 1: Digital Systems and Information Lecture 4 1Created by: Ms.Amany AlSaleh

6

Binary Coded Decimal (BCD)

Do NOT mix up conversion of a decimal number to a binary number with coding a decimal number with a BINARY CODE. 

1310 = 11012 (This is conversion) 

13 0001|0011 (This is coding)

1310 = 11012 = (00010011)BCD

The BCD value has (2 x 4 = 8 bits) while the equivalent binary number needs only 4 bits.

BCD needs more bits than its equivalent binary representation, why is it still important?

• Because people think in decimal!Created by: Ms.Amany AlSaleh

Page 7: CS151 Introduction to Digital Design Chapter 1: Digital Systems and Information Lecture 4 1Created by: Ms.Amany AlSaleh

7

Putting It All Together

BCD not very efficient

Used in early computers (40s, 50s)

Used to encode numbers for seven-segment displays.

Easier to read?

Created by: Ms.Amany AlSaleh

Page 8: CS151 Introduction to Digital Design Chapter 1: Digital Systems and Information Lecture 4 1Created by: Ms.Amany AlSaleh

8

BCD Addition

Remember! Each digit does not exceed 9 the sum cannot be greater than 9+9+1= 19.

Case 1: Case 2:

Case 3:

0001 1 0101 5(0) 0110 (0) 6

0110 6 0101 5(0) 1011 (1) 1

1000 8 1001 9(1) 0001 (1) 7

WRONG!

Note that for cases 2 and 3, adding a factor of 6 (0110) gives us the correct result.

Created by: Ms.Amany AlSaleh

Page 9: CS151 Introduction to Digital Design Chapter 1: Digital Systems and Information Lecture 4 1Created by: Ms.Amany AlSaleh

9

BCD Addition

BCD addition is therefore performed as follows

1) Add the two BCD digits together using normal binary addition

2) Check if correction is needed

a) 4-bit sum is in range of 1010 to 1111

b) carry out of MSB = 1

3) If correction is required, add 0110 to 4-bit sum to get the correct result; BCD carry out = 1

We need to add (0110)2 for any result larger than

(1001)2.

Created by: Ms.Amany AlSaleh

Page 10: CS151 Introduction to Digital Design Chapter 1: Digital Systems and Information Lecture 4 1Created by: Ms.Amany AlSaleh

10

BCD Addition (Cont.)

Remember that We need to add (0110)2 for any result

larger than (1001)2.

Case 1: 4 0100+ 5 0101

Case 2: 8 1000+ 3 0011

+011010001

No correction is needed

Add (0110)2 because result is larger than 10012

0001 | 0001 Final answer (two digits)

9 1001

11 1011

Created by: Ms.Amany AlSaleh

Page 11: CS151 Introduction to Digital Design Chapter 1: Digital Systems and Information Lecture 4 1Created by: Ms.Amany AlSaleh

11

BCD Addition (Cont.)

Given a BCD code, we use binary arithmetic to add the digits:

8 1000 Eight+5 +0101 Plus 5 13 1101 is 13 (> 9)

Note that the result is MORE THAN 9, so must be represented by two digits!

To correct the digit, add 6 1000 Eight 8

+5 +0101 Plus 5 13 1101 is 13 (> 9)

+0110 so add 6 carry = 1 0011 leaving 3 + cy

0001 | 0011 Final answer (two digits)

Created by: Ms.Amany AlSaleh

Page 12: CS151 Introduction to Digital Design Chapter 1: Digital Systems and Information Lecture 4 1Created by: Ms.Amany AlSaleh

12

BCD Addition (Cont.)

Add (2905)BCD to (1897)BCD showing carries and digit

corrections.

0001 1000 1001 0111

+ 0010 1001 0000 0101

0

1100

1 0010

1

1010

+ 0110+ 0110+ 0110

1 0000

1

1 0010

1 1000

1

0100

0100

Result: 2084

Created by: Ms.Amany AlSaleh

Page 13: CS151 Introduction to Digital Design Chapter 1: Digital Systems and Information Lecture 4 1Created by: Ms.Amany AlSaleh

13

Alphanumeric Codes

Binary codes used to represent alphabetic and numeric characters

Computers process not only numbers, but also letters (e.g.. Student name), and symbols (e.g. *, {, ., @, &,…etc).

We need to encodeencode the letters of the alphabet, in addition to symbols and numbers.

This code needs to be standard, so that computers can communicate.

Two most common are:

• ASCII, 7 bit code, 128 symbols

• EBCDIC, 8 bit code, 256 symbols

Created by: Ms.Amany AlSaleh

Page 14: CS151 Introduction to Digital Design Chapter 1: Digital Systems and Information Lecture 4 1Created by: Ms.Amany AlSaleh

14

ASCII Character Codes

American Standard Code for Information Interchange (ASCII).

ASCII is a 7-bit code, frequently used with an 8th bit for error detection (more about that in a bit).

This code is a popular code used to represent information sent as character-based data.

It uses 7-bits to code 128 characters.• 94 printing characters.

• 26 uppercase letters

• 26 lowercase letters

• 10 numbers (0,1,..,9)

• 32 special symbols ($,@, ..)

• 34 Non-printing charactersCreated by: Ms.Amany AlSaleh

Page 15: CS151 Introduction to Digital Design Chapter 1: Digital Systems and Information Lecture 4 1Created by: Ms.Amany AlSaleh

15

ASCII Character Codes (Cont.)

Created by: Ms.Amany AlSaleh

Page 16: CS151 Introduction to Digital Design Chapter 1: Digital Systems and Information Lecture 4 1Created by: Ms.Amany AlSaleh

16

ASCII Character Codes

Some non-printing characters are used for text format (e.g. BS = Backspace, CR = carriage return)

Other non-printing characters are used for information separating (e.g. file and record separators FS and RS) and communication control (e.g. STX and ETX start and end text areas).

ASCII is a 7-bit code, but computers manipulate a singe 8-bit byte ASCII characters are stored one-per-byte with the MSB set to 0.

This extra bit is sometimes used for special purposes; e.g. additional characters (like Greek) recognized by printers, or could be used for error detection. Created by: Ms.Amany AlSaleh

Page 17: CS151 Introduction to Digital Design Chapter 1: Digital Systems and Information Lecture 4 1Created by: Ms.Amany AlSaleh

17

ASCII Codes and Data Transmission

Transmission susceptible to noise

• How to keep data transmission accurate?

Created by: Ms.Amany AlSaleh

Page 18: CS151 Introduction to Digital Design Chapter 1: Digital Systems and Information Lecture 4 1Created by: Ms.Amany AlSaleh

18

Parity Bit

Parity codes are formed by concatenating a parity bit, P to each code word of C.

In an odd-parity code, the parity bit is specified so that the total number of ones is odd.

In an even-parity code, the parity bit is specified so that the total number of ones is even.

Information BitsP

1 1 0 0 0 0 1 1

Added even parity bit

0 1 0 0 0 0 1 1

Added odd parity bit

Created by: Ms.Amany AlSaleh

Page 19: CS151 Introduction to Digital Design Chapter 1: Digital Systems and Information Lecture 4 1Created by: Ms.Amany AlSaleh

19

Parity Bit

Error Detection Scenarios where even parity is used

Send ‘A’ 01000001

Two 1’s parity bit = 0 Receive 01001001

Three 1’s error

Receive 01101011

Five 1’s error

Receive 01001011

Four 1’s ? Even# ?

Sender Receiver

Control Characters:Control Characters:

Error Retransmission send NAK

No Error Receiver sends Back ACK

Odd number of errors is detected

Even number of errors is undetected

Created by: Ms.Amany AlSaleh

Page 20: CS151 Introduction to Digital Design Chapter 1: Digital Systems and Information Lecture 4 1Created by: Ms.Amany AlSaleh

20

Parity Code Example

Concatenate a parity bit to the ASCII code for the characters 0, X, and = to produce both odd-parity and even-parity codes.

Character ASCII Odd-Parity ASCII

Even-Parity ASCII

0 0110000 10110000 00110000

X 1011000 01011000 11011000

= 0111100 10111100 00111100

Created by: Ms.Amany AlSaleh

Page 21: CS151 Introduction to Digital Design Chapter 1: Digital Systems and Information Lecture 4 1Created by: Ms.Amany AlSaleh

21

UNICODE

UNICODE extends ASCII to 65,536 universal characters codes

• For encoding characters in world languages

• Available in many modern applications

• 2 byte (16-bit) code words

• See Reading Supplement – Unicode on the Companion Website

• http://www.prenhall.com/mano

Created by: Ms.Amany AlSaleh

Page 22: CS151 Introduction to Digital Design Chapter 1: Digital Systems and Information Lecture 4 1Created by: Ms.Amany AlSaleh

22

Gray Codes

Gray code is not a number system.

• It is an alternate way to represent four bit data

Only one bit changes from one decimal digit to the next

Useful for reducing errors in communication.

Can be scaled to larger numbers.

Digit Binary Gray Code 0 0000 0000 1 0001 0001 2 0010 0011 3 0011 0010 4 0100 0110 5 0101 0111 6 0110 0101 7 0111 0100 8 1000 1100 9 1001 1101 10 1010 1111 11 1011 1110 12 1100 1010 13 1101 1011 14 1110 1001 15 1111 1000Created by: Ms.Amany AlSaleh

Page 23: CS151 Introduction to Digital Design Chapter 1: Digital Systems and Information Lecture 4 1Created by: Ms.Amany AlSaleh

23

Gray Codes (Cont.)

Gray codes are minimum change codes

• From one numeric representation to the next, only one bit changes

• Primary use is in numeric input encoding apps. where we expect non-random input values changes (I.e. value n to either n-1 or n+1)• Milling machine table position

• Rotary shaft position

Created by: Ms.Amany AlSaleh