Digital Systems and Logic Design

Slides:



Advertisements
Similar presentations
Data Representation COE 202 Digital Logic Design Dr. Aiman El-Maleh
Advertisements

ICS312 Set 2 Representation of Numbers and Characters.
Princess Sumaya Univ. Computer Engineering Dept. د. بســام كحـالــه Dr. Bassam Kahhaleh.
HEXADECIMAL NUMBERS Code
Company LOGO Edit your slogan here DKT 122/3 DIGITAL SYSTEM 1 WEEK #3 NUMBER SYSTEMS, OPERATION & CODES (PART 2)
CHAPTER 2 Number Systems, Operations, and Codes
ECE 331 – Digital System Design
Chapter 1 Binary Systems 1-1. Digital Systems
Digital Fundamentals Floyd Chapter 2 Tenth Edition
Assembly Language and Computer Architecture Using C++ and Java
Assembly Language and Computer Architecture Using C++ and Java
Number Systems Decimal (Base 10) Binary (Base 2) Hexadecimal (Base 16)
CSCE 211: Digital Logic Design Chin-Tser Huang University of South Carolina.
CS2100 Computer Organisation
VIT UNIVERSITY1 ECE 103 DIGITAL LOGIC DESIGN CHAPTER I NUMBER SYSTEMS AND CODES Reference: M. Morris Mano & Michael D. Ciletti, "Digital Design", Fourth.
CS1104: Computer Organisation comp. nus. edu
Digital Fundamentals Floyd Chapter 2 Tenth Edition
S. Barua – CPSC 240 CHAPTER 2 BITS, DATA TYPES, & OPERATIONS Topics to be covered are Number systems.
MOHD. YAMANI IDRIS/ NOORZAILY MOHAMED NOOR 1 Overflow Signed binary is in fixed range -2 n-1  2 n-1 If the answer for addition/subtraction more than the.
Number System and Codes
1.6 Signed Binary Numbers.
Digital Logic Chapter 2 Number Conversions Digital Systems by Tocci.
© 2009 Pearson Education, Upper Saddle River, NJ All Rights ReservedFloyd, Digital Fundamentals, 10 th ed Digital Fundamentals Tenth Edition Floyd.
Programmable Logic Controllers
ACOE1611 Data Representation and Numbering Systems Dr. Costas Kyriacou and Dr. Konstantinos Tatas.
Computers Organization & Assembly Language
EKT 121 / 4 ELEKTRONIK DIGIT 1 CHAPTER 1 : INTRODUCTION.
#1 Lec # 2 Winter EECC341 - Shaaban Positional Number Systems A number system consists of an order set of symbols (digits) with relations.
The Digital Codes.
Morgan Kaufmann Publishers
1 Digital Systems and Binary Numbers EE 208 – Logic Design Chapter 1 Sohaib Majzoub.
EE2174: Digital Logic and Lab Professor Shiyan Hu Department of Electrical and Computer Engineering Michigan Technological University CHAPTER 2 Number.
Lec 3: Data Representation Computer Organization & Assembly Language Programming.
ECEN2102 Digital Logic Design Lecture 1 Numbers Systems Abdullah Said Alkalbani University of Buraimi.
Digital Logic Design Lecture 3 Complements, Number Codes and Registers.
ICS312 Set 1 Representation of Numbers and Characters.
Yuh-Jzer JoungDigital Systems1 Number Systems decimal number : 7397=7× × × ×10 0 a 4 a 3 a 2 a 1 a 0. a -1 a -2 = a 4 ×10 4 +a 3 ×10.
Information Representation. Digital Hardware Systems Digital Systems Digital vs. Analog Waveforms Analog: values vary over a broad range continuously.
Number Systems Decimal (Base 10) –10 digits (0,1,2,3,4,5,6,7,8,9) Binary (Base 2) –2 digits (0,1) Digits are often called bits (binary digits) Hexadecimal.
Number systems & Binary codes MODULE 1 Digital Logic Design Ch1-2 Outline of Chapter 1  1.1 Digital Systems  1.2 Binary Numbers  1.3 Number-base Conversions.
Number Systems and Codes. CS2100 Number Systems and Codes 2 NUMBER SYSTEMS & CODES Information Representations Number Systems Base Conversion Negative.
1 EENG 2710 Chapter 1 Number Systems and Codes. 2 Chapter 1 Homework 1.1c, 1.2c, 1.3c, 1.4e, 1.5e, 1.6c, 1.7e, 1.8a, 1.9a, 1.10b, 1.13a, 1.19.
ECE 301 – Digital Electronics Unsigned and Signed Numbers, Binary Arithmetic of Signed Numbers, and Binary Codes (Lecture #2)
Summer 2012ETE Digital Electronics1 Binary Arithmetic of Signed Binary Numbers.
Number Systems Decimal (Base 10) –10 digits (0,1,2,3,4,5,6,7,8,9) Binary (Base 2) –2 digits (0,1) Digits are often called bits (binary digits) Hexadecimal.
Data Representation, Number Systems and Base Conversions
ECE 331 – Digital System Design Representation and Binary Arithmetic of Negative Numbers and Binary Codes (Lecture #10) The slides included herein were.
CHAPTER 1 INTRODUCTION TO DIGITAL LOGIC
Computer Math CPS120 Introduction to Computer Science Lecture 4.
AEEE2031 Data Representation and Numbering Systems.
Tutorial: ITI1100 Dewan Tanvir Ahmed SITE, UofO
ECE 301 – Digital Electronics Representation of Negative Numbers, Binary Arithmetic of Negative Numbers, and Binary Codes (Lecture #11) The slides included.
WEEK #2 NUMBER SYSTEMS, OPERATION & CODES (PART 1)
Digital Fundamentals Tenth Edition Floyd Chapter 2 © 2008 Pearson Education.
Assoc. Prof. Dr. Ahmet Turan ÖZCERİT.  The necessity and advantages of coding  The variety of coding systems You will learn: 2.
MECH1500 Chapter 3.
NUMBER SYSTEMS AND CODES. CS Digital LogicNumber Systems and Codes2 Outline Number systems –Number notations –Arithmetic –Base conversions –Signed.
Module –I Codes: Weighted and non-weighted codes
Lecture No. 4 Computer Logic Design. Negative Number Representation 3 Options –Sign-magnitude –One’s Complement –Two’s Complement  used in computers.
Computer Math CPS120 Introduction to Computer Science Lecture 7.
Number Systems. The position of each digit in a weighted number system is assigned a weight based on the base or radix of the system. The radix of decimal.
Number Systems Decimal (Base 10) –10 digits (0,1,2,3,4,5,6,7,8,9) Binary (Base 2) –2 digits (0,1) Digits are often called bits (binary digits) Hexadecimal.
CS2100 Computer Organisation
CS2100 Computer Organisation
CHAPTER 1 : INTRODUCTION
CS1010 Programming Methodology
BEE1244 Digital System and Electronics BEE1244 Digital System and Electronic Chapter 2 Number Systems.
Digital Logic Design (ECEg3141) 2. Number systems, operations & codes 1.
ECE 331 – Digital System Design
Presentation transcript:

Digital Systems and Logic Design

General Overview This chapter is Number Systems, Operations, and Codes. Decimal numbers Binary numbers Decimal-to-binary numbers Binary arithmetic 1’s and 2’s Complements of Binary numbers Signed number Arithmetic operations with signed numbers Hexadecimal Numbers Octal Numbers Binary Coded Decimal (BCD) Digital Codes and Parity Digital System Application

Chapter Objectives Convert the number between decimal and binary. Apply arithmetic operation to binary numbers. Understand Binary Coded Decimal (BCD), Gray Code, ASCII

Decimal Numbers Decimal numbers has ten digits. (0, 1, 2, 3, …, 9) The decimal numbering system has a base of 10 with each position weighted by a factor of 10:

Binary Numbers Binary numbers has two digits, 1 and 0. The binary numbering system has a base of 2 with each position weight by a factor of 2.

Binary numbers: Example 10010 in binary is 1x24 + 0x23 + 0x22 + 1x21 + 0x20 = 18 Binary is the base 2 number system Most common in digital electronics Weight: Most Significant bit (MSB) Least Significant bit (LSB) 10010 MSB LSB

Integers and Fractional Parts Binary numbers can contain fractional parts as well as integer parts # quantization error.

Conversion: Decimal to Binary (Method 1) The decimal numbers is simply expressed as a sum of power of 2, and then 1s and 0s are written in the appropriate bit positions. 50 = 32 + 18 = 32 + 16 + 2 = 1x25 + 1x24 + 1x21 5010 = 1100102 322 = ?

Conversion: Decimal to Binary (Method 2) Repeated division Quotient Remainder 50/2 = 25 0 LSB 25/2 = 12 1 12/2 = 6 0 6/2 = 3 0 3/2 = 1 1 1/2 = 0 1 MSB stop 50 = 110010

Conversion: Binary to Decimal The simplest way is to represent the binary number as anx2n + .. + a2x22 + a1x21 + a0x20 The conversion can be done by substituting the a’s with the given bits then multiplying and adding: 110010 = 1x25 + 1x24 + 1x21 = 50

Example Convert the binary whole number 100011012 to decimal 100011012 = 27 + 23 + 22 + 20 = 128 + 8 + 4 + 1 = 14110

Example Convert the fractional binary number 0.10112 to decimal 0.1011012 = 2-1 + 2-3 + 2-4 + 2-6 = 0.5 + 0.125 + 0.0625 = 0.687510

Example Convert the binary whole number 101.01012 to decimal 101.01012 = 22 + 20 + 2-2 + 2-4 = 4 + 1 +0.25 + 0.125 + 0.0625 = 5.437510

Conversion: Fractional to Binary เลขทศนิยมฐานสิบเป็นเลขฐานสอง ผลบวกของค่าน้ำหนัก การคูณซ้ำด้วยสอง 0.782 = 0.110012 ผลบวกของค่าน้ำหนัก : การคูณซ้ำด้วยสอง : 0.782 = 0.5 + 0.25 + 0.03125 = (0.78125) 0.782 x 2 = 1.564 0.564 x 2 = 1.128 = 2-1 + 2-2 + 2-5 0.128 x 2 = 0.256 = 0.110012 0.256 x 2 = 0.512 0.512 x 2 = 1.024

Binary Number Systems Unsigned Binary Code Signed Binary Codes 2’s Complement System BCD Code Excess Codes Floating-Point System

Unsigned Binary Code Given a number N in Unsigned Binary code, find the value of N in the decimal system Use series substitution method Given a number N in the decimal system, find the value of N in the Unsigned Binary Code. Use successive division method (for integer part) Use successive multiplication method (for fraction part)

Unsigned Binary Code Can’t do. Not enough bits. 2610 = 00011010 Example 1: Represent (26)10 in Unsigned Binary Code 2610 = 11010 Example 2: Represent (26)10 in Unsigned Binary Code using 8 bits. 2610 = 00011010 Example 3: Represent (26)10 in Unsigned Binary Code using 4 bits. Can’t do. Not enough bits.

Unsigned Binary Code ( 4 bits)

Unsigned Binary Code [0, 2n-1] The Unsigned Binary Code is used to represent positive integer numbers. What is the range of values that can be represented with n bits in the Unsigned Binary Code? [0, 2n-1] How many bits are required to represent a given number N? number of bits = smallest integer greater than or equal to log(N)

Unsigned Binary Code: Arithmetic & Logic Operations Arithmetic Operations: Addition Subtraction Multiplication Division Logic Operations AND CONJUNCTION OR DISJUNCTION NOT NEGATION XOR EXCLUSIVE OR

Signed Binary Codes These are codes used to represent positive and negative numbers. Sign and Magnitude Code 1’s Complement Code 2’s Complement Code

Sign & Magnitude Code Sign & Mag. Code Decimal 01101 +13 11101 -13 The leftmost bit is the sign bit 0 for positive numbers 1 for negative numbers The remaining bits represent the magnitude of the number Example: Sign & Mag. Code Decimal 01101 +13 11101 -13 00101 +5 10101 -5

Sign &Magnitude (4 bits) What is the range of values that can be represented in S&M code with n bits?

Sign&Magnitude Example 1: Represent (26)10 in Sign & Magnitude Code. 2610 = 011010 Example 2: Represent (26)10 in Sign & Magnitude Code using 8 bits 2610 = 0001 1010 Example 3: Represent (26)10 in Sign & Magnitude Code using 5 bits. Need at least 6 bits.

Sign&Magnitude Example 1: Represent (-26)10 in Sign & Magnitude Code. 26 = 11010 -2610 = 111010 Example 2: Represent (-26)10 in Sign & Magnitude Code using 8 bits 26 = 00011010 - 2610 = 10011010 Example 3: Represent (-26)10 in Sign & Magnitude Code using 5 bits. Need at least 6 bits.

Binary Arithmetic Addition Subtraction Multiplication Division

Binary Addition Equation Recall decimal addition Binary addition

Example Add the following binary number:. (a) 10010011 + 01001011 Example Add the following binary number: (a) 10010011 + 01001011 (b) 00011111 + 00000111 1 1 (a) 1 0 0 1 0 0 1 1 + 0 1 0 0 1 0 1 1 147 + 75 1 1 1 1 1 1 = 222 1 1 1 1 1 31 (b) 0 0 0 1 1 1 1 1 + 0 0 0 0 0 1 1 1 + 7 = 3810 1 1 1

Binary Subtraction สมการทั่วไป : ตารางความจริงการลบ A0 < B0 ต้องการ 0 - 0 = 0  ผลลบ 0 ตัวยืม 0 0 - 1 = 1  ผลลบ 1 ตัวยืม 1 1 - 0 = 1  ผลลบ 1 ตัวยืม 0 1 - 1 = 0  ผลลบ 0 ตัวยืม 0 ตารางความจริงการลบ สมการทั่วไป : A0 B0 R0 B0ut 0 0 0 0 0 1 1 1 1 0 1 0 1 1 0 0 A0 < B0 ต้องการ ตัวยืม R0 : ผลต่าง Bout : ตัวยืม

Binary Multiplication A Basic Roles for Multiplication

Binary Division

1’s Complement Code Positive numbers: Negative numbers: same as in unsigned binary code pad a 0 at the leftmost bit position Negative numbers: 1. Represent the magnitude of the number in unsigned binary system 2. pad a 0 at the leftmost bit position 3. complement every bit

1’s Complement Code Example: represent 2610 in 1’s complement code 2610 = 11010 Pad a 0: = 011010 Example: Represent (-26)10 in 1’s complement code. 1. 26 = 11010 2. Pad a 0: 011010 3. Complement: 100101 (-26)10 = (100101)1’s comp

1’s Complement Code Example: Represent (-26)10 in 1’s comp. code using 8 bits 1. Represent magnitude in unsigned binary using 8 bits 26 = 0001 1010 2. Complement every bit 11100101 -2610 = (1110 0101) 1’s comp

1’s Complement Code (4 bits) What is the range of values that can be represented in S&M code with n bits? [ -(2 (n-1) -1) , 2(n-1) -1]

2’s Complement Code This is the code commonly used to represent integer numbers. Positive Numbers: same as in unsigned binary code pad with a 0 leftmost bit position Negative Numbers 1. represent magnitude in unsigned binary code 2. pad leftmost positions with 0s 3. complement every bit 4. add 1

2’s Complement Code Example 1: Represent 26 in 2’s complement code. 26 = 011010 Example 2: Represent 26 in 2’s complement code using 8 bits 26 = 00011010 Example 3: Represent 26 in 2’s complement code using 5 bits Need at least 6 bits.

2’s Complement Code Example 3: Represent - 26 in 2’s comp. Code 1. +26 = 11010 2. Pad with a 0: 011010 3. Complement: 100101 4. Add 1: + 1 --------------- 100110

2’s Complement Code Example 4: Represent - 26 in 2’s comp. Code using 8 bits 1. +26 = 11010 2. Pad 0s: 00011010 3. Complement: 11100101 4. Add 1: + 1 --------------- 11100110

2’s Complement Code More example: represent 65 in 2’s comp. Code. 65 = 0100 0001 -65 = 1011 1111

Conversion from 2’s comp code to decimal code How to convert a number in 2’s Comp. Code into the decimal code. There 2 cases: Case 1: If leftmost bit of the number is 0 => number is positive => conversion is the same as in unsigned binary code

Conversion from 2’s comp code to decimal code Case 2: If leftmost bit is 1 => the number is negative step1: complement every bit step2: add 1 step3: convert result to decimal code using same method as in unsigned binary code. Answer = the negative of the result of step 3.

2’s Complement Code (4 bits) Range of values with n bits: [ -2 (n-1), 2(n-1) -1]

1’s and 2’s Complement of Binary Numbers

Alternative Method to find 2’s Complement

Hexadecimal Notation Hexadecimal system: base 16 There are 16 digits: 0 1 2 3 4 5 6 7 8 9 A B C D E F Each Hex digit represents a group of 4 bits (i.e. half of a byte) 0000 thru 1111 Generally used as shorthand notation for binary numbers => easier to read Binary: 0101 1010 1001 1110 Decimal: 5 10 9 14 Hex: 5 A 9 E

Hexadecimal number

Hexadecimal number conversions

Addition in Hex.

Subtration in Hex.

Octal number

Binary Coded Decimal (BCD) Decimal numbers are more natural to humans. Binary numbers are natural to computers. Quite expensive to convert between the two. If little calculation is involved, we can use some coding schemes for decimal numbers. One such scheme is BCD, also known as the 8421 code. Represent each decimal digit as a 4-bit binary code.

Binary Coded Decimal (BCD) Some codes are unused, eg: (1010)BCD, (1011) BCD, …, (1111) BCD. These codes are considered as errors. Easy to convert, but arithmetic operations are more complicated. Suitable for interfaces such as keypad inputs and digital readouts. CS1104-2 Binary Coded Decimal (BCD)

Binary Coded Decimal (BCD) Examples: (234)10 = (0010 0011 0100)BCD (7093)10 = (0111 0000 1001 0011)BCD (1000 0110)BCD = (86)10 (1001 0100 0111 0010)BCD = (9472)10 Notes: BCD is not equivalent to binary. Example: (234)10 = (11101010)2 CS1104-2 Binary Coded Decimal (BCD)

BCD : Binary Coded Decimal

The Gray Code Unweighted (not an arithmetic code). Only a single bit change from one code number to the next. Good for error detection. Q. How to generate 5-bit standard Gray code? Q. How to generate n-bit standard Gray code? CS1104-2 The Gray Code

The Gray Code 0000 0001 0100 0101 0111 0110 0010 0011 0001 0000 1100 1101 1111 1110 1010 1011 1001 1000 0001 0000 0011 0010 0010 0011 0001 0000 0110 0111 0101 0100 Generating 4-bit standard Gray code. CS1104-2 The Gray Code

The Gray Code sensors mis-aligned sensors Gray coded: 111  101 0 0 1 0 0 0 0 1 0 0 1 1 1 0 1 1 1 0 1 1 1 1 0 0 sensors 1 0 1 1 1 1 0 0 0 1 0 0 0 1 0 0 0 1 0 1 1 1 1 0 mis-aligned sensors Gray coded: 111  101 Binary coded: 111  110  000 0 0 0 1 1 1 0 1 0 0 0 1 1 0 1 0 1 1 1 0 0 1 1 0 mis-aligned sensors CS1104-2 The Gray Code

Binary-to-Gray Code Conversion Retain most significant bit. From left to right, add each adjacent pair of binary code bits to get the next Gray code bit, discarding carries. Example: Convert binary number 10110 to Gray code. (10110)2 = (11101)Gray CS1104-2 Binary-to-Gray Code Conversion

Gray-to-Binary Conversion Retain most significant bit. From left to right, add each binary code bit generated to the Gray code bit in the next position, discarding carries. Example: Convert Gray code 11011 to binary. (11011)Gray = (10010)2 CS1104-2 Gray-to-Binary Conversion

Error Detection Codes Sometimes, it is not enough to do error detection. We may want to do error correction. Error correction is expensive. In practice, we may use only single-bit error correction. Popular technique: Hamming Code (not covered). CS1104-2 Error Detection Codes

Gray code

Binary to Gray Conversion

Gray to Binary

Other Decimal Codes Self-complementing codes: excess-3, 84-2-1, 2*421 codes. Error-detecting code: biquinary code (bi=two, quinary=five). CS1104-2 Other Decimal Codes

Self-Complementing Codes Examples: excess-3, 84-2-1, 2*421 codes. The codes that represent the pair of complementary digits are complementary of each other. Excess-3 code 0: 0011 1: 0100 2: 0101 3: 0110 4: 0111 5: 1000 6: 1001 7: 1010 8: 1011 9: 1100 241: 0101 0111 0100 758: 1010 1000 1011 CS1104-2 Self-Complementing Codes

Alphanumeric Codes Apart from numbers, computers also handle textual data. Character set frequently used includes: alphabets: ‘A’ .. ‘Z’, and ‘a’ .. ‘z’ digits: ‘0’ .. ‘9’ special symbols: ‘$’, ‘.’, ‘,’, ‘@’, ‘*’, … non-printable: SOH, NULL, BELL, … Usually, these characters can be represented using 7 or 8 bits. CS1104-2 Alphanumeric Codes

Alphanumeric Codes Two widely used standards: ASCII (American Standard Code for Information Interchange) EBCDIC (Extended BCD Interchange Code) ASCII: 7-bit, plus a parity bit for error detection (odd/even parity). EBCDIC: 8-bit code. CS1104-2 Alphanumeric Codes

Alphanumeric Codes ASCII table: CS1104-2 Alphanumeric Codes

Error Detection Codes Errors can occur data transmission. They should be detected, so that re-transmission can be requested. With binary numbers, usually single-bit errors occur. Example: 0010 erroneously transmitted as 0011, or 0000, or 0110, or 1010. Biquinary code uses 3 additional bits for error-detection. For single-error detection, one additional bit is needed. CS1104-2 Error Detection Codes

Error Detection Codes Parity bit. Example: Odd parity. Even parity: additional bit supplied to make total number of ‘1’s even. Odd parity: additional bit supplied to make total number of ‘1’s odd. Example: Odd parity. Parity bits CS1104-2 Error Detection Codes

Error Detection Codes Parity bit can detect odd number of errors but not even number of errors. Example: For odd parity numbers, 10011  10001 (detected) 10011  10101 (non detected) Parity bits can also be applied to a block of data: Column-wise parity Row-wise parity CS1104-2 Error Detection Codes

Error Detection Codes Sometimes, it is not enough to do error detection. We may want to do error correction. Error correction is expensive. In practice, we may use only single-bit error correction. Popular technique: Hamming Code (not covered). CS1104-2 Error Detection Codes

Alphanumeric Codes

ASCII

Parity Method for error checking

Put it together