Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS151 Introduction to Digital Design

Similar presentations


Presentation on theme: "CS151 Introduction to Digital Design"— Presentation transcript:

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

2 Created by: Ms.Amany AlSaleh
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

3 Created by: Ms.Amany AlSaleh
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

4 Created by: Ms.Amany AlSaleh
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

5 Binary Coded Decimal (BCD)
Each decimal digit is represented by 4 bits. A number with n decimal digits requires 4n bits in BCD Example: (396)10 = ( )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 0000 5 0101 1 0001 6 0110 2 0010 7 0111 3 0011 8 1000 4 0100 9 1001 Created 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 = (This is conversion)  13  0001|0011 (This is coding)  1310 = = ( )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

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

8 Created by: Ms.Amany AlSaleh
BCD Addition Remember! Each digit does not exceed 9  the sum cannot be greater than 9+9+1= 19. Case 1: Case 2: 0001 1 0101 5 (0) (0) 6 0110 6 0101 5 (0) (1) 1 WRONG! Case 3: 1000 8 1001 9 (1) (1) 7 Note that for cases 2 and 3, adding a factor of 6 (0110) gives us the correct result. Created by: Ms.Amany AlSaleh

9 Created by: Ms.Amany AlSaleh
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

10 Final answer (two digits) Created by: Ms.Amany AlSaleh
BCD Addition (Cont.) Remember that We need to add (0110)2 for any result larger than (1001)2. Case 1: 9 1001 No correction is needed Case 2: 11 1011 +0110 Add (0110)2 because result is larger than 10012 10001 0001 | 0001 Final answer (two digits) Created by: Ms.Amany AlSaleh

11 Final answer (two digits) Created by: Ms.Amany AlSaleh
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 8 +5 1000 Eight +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

12 Created by: Ms.Amany AlSaleh
BCD Addition (Cont.) Add (2905)BCD to (1897)BCD showing carries and digit corrections. 1 1 1 0100 1 0010 1010 1100 + 0110 + 0110 + 0110 0100 Result: 4 8 2 Created by: Ms.Amany AlSaleh

13 Created by: Ms.Amany AlSaleh
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 encode 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

14 Created by: Ms.Amany AlSaleh
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 characters Created by: Ms.Amany AlSaleh

15 ASCII Character Codes (Cont.)
Created by: Ms.Amany AlSaleh

16 Created by: Ms.Amany AlSaleh
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

17 ASCII Codes and Data Transmission
Transmission susceptible to noise How to keep data transmission accurate? Created by: Ms.Amany AlSaleh

18 Created by: Ms.Amany AlSaleh
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 Bits P Added even parity bit Added odd parity bit Created by: Ms.Amany AlSaleh

19 Created by: Ms.Amany AlSaleh
Parity Bit Error Detection Scenarios where even parity is used Send ‘A’ Two 1’s parity bit = 0 Receive Three 1’s  error Receive Five 1’s  error Receive Four 1’s  ? Even# ? Sender Receiver Odd number of errors is detected Even number of errors is undetected Control Characters: Error  Retransmission send NAK No Error  Receiver sends Back ACK Created by: Ms.Amany AlSaleh

20 Created by: Ms.Amany AlSaleh
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 X = Created by: Ms.Amany AlSaleh

21 Created by: Ms.Amany AlSaleh
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 Created by: Ms.Amany AlSaleh

22 Created by: Ms.Amany AlSaleh
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 0000 1 0001 2 0010 0011 3 4 0100 0110 5 0101 0111 6 7 8 1000 1100 9 1001 1101 10 1010 1111 11 1011 1110 12 13 14 15 Created by: Ms.Amany AlSaleh

23 Created by: Ms.Amany AlSaleh
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


Download ppt "CS151 Introduction to Digital Design"

Similar presentations


Ads by Google