Digital Systems and Binary Numbers

Similar documents
Lecture (02) Operations on numbering systems

Logic Circuits I ECE 1411 Thursday 4:45pm-7:20pm. Nathan Pihlstrom.

Chapter 1. Digital Systems and Binary Numbers

CHAPTER TWO. Data Representation ( M.MORRIS MANO COMPUTER SYSTEM ARCHITECTURE THIRD EDITION ) IN THIS CHAPTER

Korea University of Technology and Education

Digital Systems and Binary Numbers

Lecture (03) Binary Codes Registers and Logic Gates

CS 121 Digital Logic Design. Chapter 1. Teacher Assistant. Hadeel Al-Ateeq

DIGITAL SYSTEM DESIGN

BINARY SYSTEM. Binary system is used in digital systems because it is:

Digital Systems and Binary Numbers

Lecture 2: Number Systems

Lecture (01) Digital Systems and Binary Numbers By: Dr. Ahmed ElShafee

Binary Systems and Codes

Digital Fundamentals

Chap 1. Digital Computers and Information

Lecture (01) Introduction Number Systems and Conversion (1)

Computer Sc. & IT. Digital Logic. Computer Sciencee & Information Technology. 20 Rank under AIR 100. Postal Correspondence

Logic and Computer Design Fundamentals. Chapter 1 Digital Computers and Information

Digital Fundamentals. CHAPTER 2 Number Systems, Operations, and Codes

Review of Number Systems

CHW 261: Logic Design

Chapter 3: Number Systems and Codes. Textbook: Petruzella, Frank D., Programmable Logic Controllers. McGraw Hill Companies Inc.

DIGITAL SYSTEM FUNDAMENTALS (ECE 421) DIGITAL ELECTRONICS FUNDAMENTAL (ECE 422) COURSE / CODE NUMBER SYSTEM

LOGIC DESIGN. Dr. Mahmoud Abo_elfetouh

EEM 232 Digital System I

ECE 20B, Winter Purpose of Course. Introduction to Electrical Engineering, II. Administration

Chapter 2. Data Representation in Computer Systems

MC1601 Computer Organization

Computer Organization

D I G I T A L C I R C U I T S E E

Excerpt from: Stephen H. Unger, The Essence of Logic Circuits, Second Ed., Wiley, 1997

Numbering systems. Dr Abu Arqoub

Digital Fundamentals

Digital Fundamentals

DIGITAL ARITHMETIC: OPERATIONS AND CIRCUITS

Numeral Systems. -Numeral System -Positional systems -Decimal -Binary -Octal. Subjects:

Chapter 1 Review of Number Systems


Number Systems and Conversions UNIT 1 NUMBER SYSTEMS & CONVERSIONS. Number Systems (2/2) Number Systems (1/2) Iris Hui-Ru Jiang Spring 2010

Electronics Engineering ECE / E & T

Positional Number System

Number System. Introduction. Decimal Numbers

UNIT - I: COMPUTER ARITHMETIC, REGISTER TRANSFER LANGUAGE & MICROOPERATIONS

SE311: Design of Digital Systems

Binary Codes. Dr. Mudathir A. Fagiri

Binary Addition. Add the binary numbers and and show the equivalent decimal addition.

Electronic Data and Instructions

Digital Logic Lecture 2 Number Systems

Number Systems Base r

in this web service Cambridge University Press

Ms Sandhya Rani Dash UNIT 2: NUMBER SYSTEM AND CODES. 1.1 Introduction

9/3/2015. Data Representation II. 2.4 Signed Integer Representation. 2.4 Signed Integer Representation

Number Systems. Dr. Tarek A. Tutunji Philadelphia University, Jordan

COE 202: Digital Logic Design Number Systems Part 2. Dr. Ahmad Almulhem ahmadsm AT kfupm Phone: Office:

Number representations

Combinational Logic. Prof. Wangrok Oh. Dept. of Information Communications Eng. Chungnam National University. Prof. Wangrok Oh(CNU) 1 / 93

Agenda EE 224: INTRODUCTION TO DIGITAL CIRCUITS & COMPUTER DESIGN. Lecture 1: Introduction. Go over the syllabus 3/31/2010

DLD VIDYA SAGAR P. potharajuvidyasagar.wordpress.com. Vignana Bharathi Institute of Technology UNIT 1 DLD P VIDYA SAGAR

NUMBER SYSTEMS AND CODES

10.1. Unit 10. Signed Representation Systems Binary Arithmetic

Moodle WILLINGDON COLLEGE SANGLI. ELECTRONICS (B. Sc.-I) Introduction to Number System

Digital Systems COE 202. Digital Logic Design. Dr. Muhamed Mudawar King Fahd University of Petroleum and Minerals

IT 1204 Section 2.0. Data Representation and Arithmetic. 2009, University of Colombo School of Computing 1

CHAPTER V NUMBER SYSTEMS AND ARITHMETIC

MACHINE LEVEL REPRESENTATION OF DATA

COMBINATIONAL LOGIC CIRCUITS

Chapter 3: part 3 Binary Subtraction

Number Systems CHAPTER Positional Number Systems

Chapter 4 Arithmetic Functions

CS & IT Conversions. Magnitude 10,000 1,

Chapter 2. Positional number systems. 2.1 Signed number representations Signed magnitude

Computer Organization

Dec Hex Bin ORG ; ZERO. Introduction To Computing

Digital Logic. The Binary System is a way of writing numbers using only the digits 0 and 1. This is the method used by the (digital) computer.

Bits, Words, and Integers

(+A) + ( B) + (A B) (B A) + (A B) ( A) + (+ B) (A B) + (B A) + (A B) (+ A) (+ B) + (A - B) (B A) + (A B) ( A) ( B) (A B) + (B A) + (A B)

UNIT 2 NUMBER SYSTEM AND PROGRAMMING LANGUAGES

UNIT 7A Data Representation: Numbers and Text. Digital Data

Chapter 2 Number Systems and Codes Dr. Xu

Binary. Hexadecimal BINARY CODED DECIMAL

Slide Set 1. for ENEL 339 Fall 2014 Lecture Section 02. Steve Norman, PhD, PEng

Chapter 2: Number Systems

COMPUTER ORGANIZATION AND ARCHITECTURE

Module -10. Encoder. Table of Contents

Announcement. (CSC-3501) Lecture 3 (22 Jan 2008) Today, 1 st homework will be uploaded at our class website. Seung-Jong Park (Jay)

Level ISA3: Information Representation

Thus needs to be a consistent method of representing negative numbers in binary computer arithmetic operations.

Chapter 2. Data Representation in Computer Systems

CHAPTER 2 (b) : AND CODES

Memory Addressing, Binary, and Hexadecimal Review

The Gray Code. Script

Number Systems Prof. Indranil Sen Gupta Dept. of Computer Science & Engg. Indian Institute of Technology Kharagpur Number Representation

LOGIC CIRCUITS. Kirti P_Didital Design 1

UNIT-II. Part-2: CENTRAL PROCESSING UNIT

Fundamentals of Programming (C)

CHAPTER 2 Data Representation in Computer Systems

ELECTRICAL AND COMPUTER ENGINEERING DEPARTMENT, OAKLAND UNIVERSITY ECE-278: Digital Logic Design Fall Notes - Unit 4. hundreds.

COMPUTER ARCHITECTURE AND ORGANIZATION. Operation Add Magnitudes Subtract Magnitudes (+A) + ( B) + (A B) (B A) + (A B)

CHAPTER 2 Data Representation in Computer Systems

Transcription:

Digital Systems and Binary Numbers Prof. Wangrok Oh Dept. of Information Communications Eng. Chungnam National University Prof. Wangrok Oh(CNU) 1 / 51

Overview 1 Course Summary 2 Binary Numbers 3 Number-Base Conversions 4 Octal and Hexadecimal Numbers 5 Complements of Numbers 6 Signed Binary Numbers 7 Binary Codes 8 Binary Storage and Registers 9 Binary Logic Prof. Wangrok Oh(CNU) 2 / 51

Course Summary Lecturer: Wangrok Oh Office: Room 421-1, Engineering Building #3 T. 042-821-5891 E. kingrock@cnu.ac.kr Text Book M. Morris Mano and Michael D. Ciletti, Digital Design with an Introduction to the Verilog HDL, 5th ed., Pearson Course Objective Equip the students with a solid understanding of digital systems and to introduce them to the methodology of modern digital design Course Homepage: http://lamarr.cnu.ac.kr/cslab/class.html Grading (tantative) Midterm Exam. (30 %), Final Exam. (40 %), Quiz (20 %), Homework (10 %) Prof. Wangrok Oh(CNU) Course Summary 3 / 51

Binary Numbers A decimal number 7,392 7 10 3 + 3 10 2 + 9 10 1 + 2 10 0 A number with a decimal point: a 5 a 4 a 3 a 2 a 1 a 0.a 1 a 2 a 3 a 5 10 5 + a 4 10 4 + a 3 10 3 + a 2 10 2 + a 1 10 1 + a 0 10 0 + a 1 10 1 + a 2 10 2 + a 3 10 3 The decimal number system is said to be of base or radix 10 The radix point (the decimal point when 10 is the radix) distinguishes positive powers of 10 from negative powers of 10 Binary number system is a different number system The coefficients have only two possible values: 0 and 1 Each coefficient a j is multiplied by a power of the radix, 2 j and the results are added to obtain the decimal equivalent of the number Binary number 11010.11 1 2 4 + 1 2 3 + 0 2 2 + 1 2 1 + 0 2 0 + 1 2 1 + 1 2 2 = 26.75 Prof. Wangrok Oh(CNU) Binary Numbers 4 / 51

Binary Numbers There are many different number systems In general, a number system with a base r system has coefficients multiplied by powers of r a n r n + a n 1 r n 1 + + a 1 r + a 0 + a 1 r 1 + + a m r m The coefficients a j range in value from 0 to r 1 To distinguish between numbers of different bases, we enclose the coefficients in parentheses and write a subscript equal to the base used (4021.2) 5 = 4 5 3 + 0 5 2 + 2 5 1 + 1 5 0 + 2 5 1 = (511.4) 10 (127.4) 8 = 1 8 2 + 2 8 1 + 7 8 0 + 4 8 1 = (87.5) 10 What should we do when the base of the number is greater than 10? Hexadecimal number system: Base=16 The first 10 digits are borrowed from the decimal number systems Prof. Wangrok Oh(CNU) Binary Numbers 5 / 51

Binary Numbers The letters A, B, C, D, E and F are used for the digits 10, 11, 12, 13, 14 and 15, respectively (B65F) 16 = 11 16 3 + 6 16 2 + 5 16 1 + 15 16 0 = (46687) 10 Hexadecimal number system is used commonly to represent long strings of bits 1011 0110 0101 1111 = (B65F) 16 B 6 5 F The digits in a binary number are called bits When a bit is equal to 0, it does not contribute to the sum during the conversion Adding only the numbers with powers of two corresponding to the bits equal to 1 (110101) 2 = 1 2 5 +1 2 4 +1 2 2 +1 2 0 = 32+16+4+1 = (53) 10 In computer work, 2 10 is referred to as K (kilo), 2 20 as M (mega), 2 30 as G (giga) and 2 40 as T (tera) A byte is equal to eight bits Prof. Wangrok Oh(CNU) Binary Numbers 6 / 51

in the addresses, instructions, and data in digital systems. partial For example, product: B65F is used to 1011 represent 1011011001010000. As noted before, the digits in a binary number are called bits. product: When a bit is equal 110111 to 0, it does not contribute to the sum during the conversion. Therefore, the conversion from binary Table 1.1 to decimal can be obtained by adding only the numbers with powers of two Powers of Two corresponding to the bits that are equal Powers to 1. of For Two example, n 2 n (110101) n 2 n n 2 n 2 = 32 + 16 + 4 + 1 = (53) 10 Binary Numbers There 0 are four 1 s 1 in the binary 8 number. 256 The corresponding 16 decimal 65,536 number is the sum of the four 1 powers of 2 two. Zero 9 and the first 51224 numbers obtained 17 from 131,072 2 to the power of n are listed 2 in Table 41.1. In computer 10 work, 1,024 2 10 (1K) is referred 18 to as K (kilo), 262,144 2 20 as M (mega), 2 30 as G (giga), 3 and 2 8 40 as T (tera). 11 Thus, 4K 2,048 = 2 12 = 4,09619 and 16M = 524,288 2 = 16,777,216. Computer 4 capacity 16 is usually 12 given in bytes. 4,096 A (4K) byte is equal 20 to eight 1,048,576 bits and (1M) can accommodate (i.e., 5 represent 32 the code 13 of) one 8,192 keyboard character. 21 A computer 2,097,152 hard disk with four gigabytes 6 of storage 64 has a 14 capacity 16,384 of 4G = 2 32 bytes 22 (approximately 4,194,304 4 billion bytes). A terabyte 7 is 1024 128 gigabytes, approximately 15 32,768 1 trillion bytes. 23 8,388,608 Arithmetic operations with numbers in base r follow the same rules as for decimal numbers. Arithmetic When operations a base other with than the numbers familiar in base base 10 is rused, follow one the must same be careful rulesto use only the r allowable digits. Examples of addition, subtraction, and multiplication of two as binary for decimal numbers numbers are as follows: augend: 101101 minuend: 101101 multiplicand: 1011 addend: +100111 subtrahend: -100111 multiplier: * 101 sum: 1010100 difference: 000110 1011 0000 partial product: 1011 product: 110111 Table 1.1 Prof. Wangrok Powers Oh(CNU) of Two Binary Numbers 7 / 51

Number-Base Conversions Representations of a number in a different radix are said to be equivalent if they have the same decimal representations A number in base r to decimal: Expanding the number in a power series and adding all the terms A decimal number to a number in base r: Dividing the number and all successive quotients by r and accumulating the remainders Example (Convert Decimal 41 to Binary) 1 41 is divided by 2 to give an integer quotient of 20 and the remainder of 1 2 The quotient, 20 is again divided by 2 to give a new quotient 10 and the remainder 0 3 Repeat this until a new quotient is 0 4 The coefficients of the desired binary number are obtained from the remainders Prof. Wangrok Oh(CNU) Number-Base Conversions 8 / 51

Number-Base Conversions 41 = 2 20 + 1 a 0 = 1 20 = 2 10 + 0 a 1 = 0 10 = 2 5 + 0 a 2 = 0 5 = 2 2 + 1 a 3 = 1 2 = 2 1 + 0 a 4 = 0 1 = 2 0 + 1 a 5 = 1 The answer is (41) 10 = (a 5 a 4 a 3 a 2 a 1 a 0 ) 2 = (101001) 2 41 = 2 20 + 1 = 2 2 10 + 1 = 2 2 2 5 + 1 = 2 2 2 (2 2 + 1) + 1 = 2 5 + 2 3 + 2 0 Prof. Wangrok Oh(CNU) Number-Base Conversions 9 / 51

Number-Base Conversions The arithmetic process can be manipulated more conveniently Integer Quotient Remainder 41 20 1 10 0 5 0 2 1 1 0 0 1 Prof. Wangrok Oh(CNU) Number-Base Conversions 10 / 51

Number-Base Conversions Example (Convert Decimal 153 to Octal) The required base r is 8 The answer is (153) 10 = (231) 8 Integer Quotient Remainder 153 19 1 2 3 0 2 The conversion of a decimal fraction to binary is accomplished by a method similar to that used for integers Multiplication is used instead of division and integers instead of remainders are accumulated Prof. Wangrok Oh(CNU) Number-Base Conversions 11 / 51

Number-Base Conversions Example (Convert (0.6875) 10 to Binary) 1 0.6875 is multiplied by 2 to give an integer and a fraction 2 New fraction is multiplied by 2 to give a new integer and a new fraction 3 Repeat this until the fraction becomes 0 or until the number of digits has sufficient accuracy 0.6875 2 = 1 + 0.3750 a 1 = 1 0.3750 2 = 0 + 0.7500 a 2 = 0 0.7500 2 = 1 + 0.5000 a 3 = 1 0.5000 2 = 1 + 0.0000 a 4 = 1 Prof. Wangrok Oh(CNU) Number-Base Conversions 12 / 51

Number-Base Conversions 0.6875 = 1 (1 + 0.3750) 2 (1 + 12 ) (0 + 0.7500) = 1 2 ( (0 + 12 (1 + 0.5000) ) ) = 1 1 + 1 2 2 ( = 1 1 + 1 2 2 = 1 2 + ( 1 2) 3 + = (0.1011) 2 0 + 1 2 ( ) 4 1 2 ( 1 + 1 ) ) 2 (1 + 0) Prof. Wangrok Oh(CNU) Number-Base Conversions 13 / 51

Number-Base Conversions Example (Convert (0.513) 10 to Octal) 0.513 8 = 4.104 0.104 8 = 0.832 0.832 8 = 6.656 0.656 8 = 5.248 0.248 8 = 1.984 0.984 8 = 7.872 The answer, to seven significant figures, is obtained from the integer part of the products: (0.406517 ) 8 Prof. Wangrok Oh(CNU) Number-Base Conversions 14 / 51

Number-Base Conversions The conversion of decimal numbers with both integer and fraction parts is done by converting the integer and the fraction separately and then combining the two answers For example, (41.6875) 10 = (101001.1011) 2 Prof. Wangrok Oh(CNU) Number-Base Conversions 15 / 51

Octal and Hexadecimal Numbers Too long binary sequence is not easy to recognize The conversion from and to binary, octal and hexadecimal plays an important role in digital computers Since 2 3 = 8 and 2 4 = 16, each octal and hexadecimal digit correspond to 3 and 4 binary digits, respectively Binary to octal is easily accomplished by partitioning the binary number into groups of three digits starting from the binary point and proceeding to the left and to the right ( 10 2 110 6 001 1 101 5 011. 111 3 7 100 4 000 0 110 ) 2 = (26153.7406) 8 6 Binary to hexadecimal is accomplished by partitioning the binary number into groups of four digits starting from the binary point and proceeding to the left and to the right ( 10 1100 0110 1011. 1111 0010 ) 2 = (2C6B.F2) 16 2 C 6 B F 2 Prof. Wangrok Oh(CNU) Octal and Hexadecimal Numbers 16 / 51

Octal and Hexadecimal Numbers Conversion from octal or hexadecimal to binary is done by reversing the preceding procedure (673.124) 8 = ( 110 6 (306.D) 15 = (0011 3 111 7 0000 0 011. 001 3 1 0110. 1101 6 D 010 2 ) 2 100 4 ) 2 Prof. Wangrok Oh(CNU) Octal and Hexadecimal Numbers 17 / 51

Octal and Hexadecimal Numbers Section 1.4 Octal and Hexadecimal Numbers 9 Table 1.2 Numbers with Different Numbers Bases with Different Bases Decimal (base 10) Binary (base 2) Octal (base 8) Hexadecimal (base 16) 00 0000 00 0 01 0001 01 1 02 0010 02 2 03 0011 03 3 04 0100 04 4 05 0101 05 5 06 0110 06 6 07 0111 07 7 08 1000 10 8 09 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 Prof. Wangrok Oh(CNU) Octal and Hexadecimal Numbers 18 / 51

Complements of Numbers Complements are used in digital computers to simplify the subtraction operation and logical manipulation Simplifying operations leads to simpler, less expensive circuits to implement the operations There are two types of complements for each base-r system 1 Radix complement: r s complement 2 Diminished radix complement: (r 1) s complement Definition (Diminished Radix Complement) Given a number N in base r having n digits, the (r 1) s complement of N is defined as (r n 1) N For decimal numbers: r = 10 (r 1) = 9 9 s complement of N = (10 n 1) N 9 s complement is obtained by subtracting each digit from 9 Prof. Wangrok Oh(CNU) Complements of Numbers 19 / 51

Complements of Numbers For binary numbers: r = 2 (r 1) = 1 1 s complement of N = (2 n 1) N Since 1 0 = 1 and 1 1 = 0, the 1 s complement of a binary number is formed by changing 1 s to 0 s and 0 s to 1 s Example (Diminished Radix Complement) The 9 s complement of 546700 999999 546700 = 453299 The 9 s complement of 012398 999999 012398 = 987601 The 1 s complement of 1011000 1111111 1011000 = 0100111 The 1 s complement of 0101101 1111111 0101101 = 1010010 Prof. Wangrok Oh(CNU) Complements of Numbers 20 / 51

Complements of Numbers Definition (Radix Complement) Given a number N in base r having n digits, the r s complement of N is defined as r n N for N 0 and as 0 for N = 0 Note that r n N = [ (r n 1) N ] + 1 Comparing with the (r 1) s complement, the r s complement is obtained by adding 1 to the (r 1) s complement 10 s complement of N can be formed also as follows: 1 Leaving all least significant 0 s unchanged 2 Subtracting the first nonzero least significant digit from 10 3 Subtracting all higher significant digits from 9 012398 987602 246700 753300 Prof. Wangrok Oh(CNU) Complements of Numbers 21 / 51

Complements of Numbers 2 s complement of N can be formed also as follows: 1 Leaving all least significant 0 s and the first 1 unchanged 2 Replacing 1 s with 0 s and 0 s with 1 s in all other higher significant digits 1101100 0010100 0110111 1001001 If the original number N contains a radix point: 1 The radix point should be removed temporarily in order to form the r s or (r 1) s complement 2 Radix point is then restored to the complemented number in the same relative position The complement of the complement restores the number to its original value r n (r n N) = N Prof. Wangrok Oh(CNU) Complements of Numbers 22 / 51

Complements of Numbers Subtraction with complement The direct method of subtraction is efficient when people perform subtraction with paper and pencil When subtraction is implemented with digital hardware, the method is less efficient than the method that uses complements Subtraction of two n-digit unsigned numbers (M N) in base r 1 Add the minuend M to the r s complement of the subtrahend N: M + (r n N) = M N + r n 2 If M N, the sum will produce an end carry r n which can be discarded 3 If M < N, the sum does not produce an end carry and is equal to r n (N M) which is the r s complement of (N M) To obtain the answer, take the r s complement of the sum and place a negative sign in front Prof. Wangrok Oh(CNU) Complements of Numbers 23 / 51

Complements of Numbers Example (72532 3250) M = 72532 10 s complement of N = 96750 Sum = 169282 Discard end carry 10 5 = 69282 Example (3250 72532) M = 03250 10 s complement of N = 27468 Sum = 30718 10 s complement of the sum = 69282 (10 s complement of the sum) = 69282 Prof. Wangrok Oh(CNU) Complements of Numbers 24 / 51

Complements of Numbers Example (X = 1010100 and Y = 1000011) 1 (X Y ) X = 1010100 2 s complement of Y = 0111101 Sum = 10010001 Discard end carry 2 7 = 0010001 2 (Y X) Y = 1000011 2 s complement of X = 0101100 Sum = 1101111 2 s complement of the sum = 0010001 (2 s complement of the sum) = 0010001 Prof. Wangrok Oh(CNU) Complements of Numbers 25 / 51

Complements of Numbers Subtraction of unsigned numbers can also be done by means of the (r 1) s complement Remember that the (r 1) s complement is one less than the r s complement The sum is one less than the correct difference when an end carry occurs Removing the end carry and adding 1 to the sum Prof. Wangrok Oh(CNU) Complements of Numbers 26 / 51

Complements of Numbers Example (X = 1010100 and Y = 1000011) 1 (X Y ) X = 1010100 1 s complement of Y = 0111100 Sum = 10010000 Discard end carry 2 7 = 0010000 Add end-around carry = 1 Answer = 0010001 2 (Y X) Y = 1000011 1 s complement of X = 0101011 Sum = 1101110 1 s complement of the sum = 0010001 (1 s complement of the sum) = 0010001 Prof. Wangrok Oh(CNU) Complements of Numbers 27 / 51

Signed Binary Numbers To represent negative numbers, we need a notation for negative values In ordinary arithmetic, a negative number is indicated by a minus sign and a positive number by a plus sign Because of hardware limitations, computers must represent everything with binary digits, 0 or 1 The leftmost position of the number is used to represent the sign Sign bit 0 for positive and 1 for negative Signed The leftmost bit represents the sign and the rest of the bits represent the number Unsigned The leftmost bit is the most significant bit of the number 01001: Signed +9/Unsigned 9 11001: Signed 9/Unsigned 25 The representation of the signed numbers in the above example is referred to as the signed-magnitude convention Prof. Wangrok Oh(CNU) Signed Binary Numbers 28 / 51

Signed Binary Numbers When arithmetic operations are implemented in a computer, it is more convenient to use a different system, referred to as the signed-complement system A negative number is indicated by its complement Note that the signed-magnitude system negates a number by changing its sign Signed-complement system negates a number by taking its complement The signed-complement system can use either the 1 s or the 2 s complement 2 s complement is the most common Consider the number 9 represented in binary with eight bits +9 = 00001001 9 = 10001001 with signed-magnitude 9 = 11110110 with signed 1 s complement 9 = 11110111 with signed 2 s complement Prof. Wangrok Oh(CNU) Signed Binary Numbers 29 / 51

Signed Binary Numbers 16 Chapter 1 Digital Systems and Binary Numbers Table 1.3 Signed Binary Numbers Decimal Signed Binary Numbers Signed 2 s Complement Signed 1 s Complement Signed Magnitude +7 0111 0111 0111 +6 0110 0110 0110 +5 0101 0101 0101 +4 0100 0100 0100 +3 0011 0011 0011 +2 0010 0010 0010 +1 0001 0001 0001 +0 0000 0000 0000-0 1111 1000-1 1111 1110 1001-2 1110 1101 1010-3 1101 1100 1011-4 1100 1011 1100-5 1011 1010 1101-6 1010 1001 1110-7 1001 1000 1111-8 1000 The positive numbers in all three representations are identical The signed-2 s complement system has only one representation for 0 representation of negative numbers. The same procedures can be applied to the signed 1 s complement system by including the end around carry as is done with unsigned numbers. Prof. Wangrok Oh(CNU) Signed Binary Numbers 30 / 51

Signed Binary Numbers With four bits, we can represent 16 binary numbers In the 1 scomplement, there are eight positive numbers and eight negative numbers In the 2 s-complement, there are seven positive numbers, one zero and eight negative numbers Arithmetic Addition The addition of two signed 2 s Section complement 1.6 Signed binary Binary numbers Numbers is 17 obtained from the addition of the two numbers including their sign Numerical A examples carry out of for the addition sign-bit follow: position is discarded + 6 00000110-6 11111010 +13 00001101 +13 00001101 +19 00010011 + 7 00000111 + 6 00000110-6 11111010-13 11110011-13 11110011-7 11111001-19 11101101 Note that negative numbers must be initially in 2 s complement form and that if the sum obtained after the addition is negative, it is in 2 s complement form. For example, -7 is Prof. Wangrok Oh(CNU) Signed Binary Numbers 31 / 51

Signed Binary Numbers Arithmetic Subtraction Subtraction procedure Take the 2 s complement of the subtrahend including the sign bit Add it to the minuend including the sign bit A carry out of the sign-bit position is discarded This procedure is adopted because a subtraction can be changed to an addition (±A) (±B) = (±A) + ( B) Changing a positive number to a negative number is easily done by taking the 2 s complement ( 6) ( 13) = +7 11111010 11110011 ( 6) + (+13) = +7 11111010 + 00001101 = 100000111 Removing the end carry, we obtain the answer 00000111 Prof. Wangrok Oh(CNU) Signed Binary Numbers 32 / 51

Binary Codes number in BCD is the same as its equivalent binary number only when the number is between 0 and 9. A BCD number greater than 10 looks different from its equivalent binary number, even though both contain 1 s and 0 s. Moreover, the binary combinations 1010 through 1111 are not used and have no meaning in BCD. C o n s i d e r d e c i m a l 185 and its corresponding value in BCD and binary: An n-bit binary code (185) is a group of n bits 2 n 10 = (0001 1000 0101) BCD = (10111001) distinct 2 combinations of 1 s and 0 s 2 n elements can be represented Binary Coded Decimal Code Table 1.4 Binary Coded Decimal (BCD) Commonly referred to as (8421-) BCD Decimal BCD Each group of 4 bits representing one decimal digit Symbol Digit 0 0000 1 0001 2 0010 3 0011 4 0100 5 0101 6 0110 7 0111 8 1000 9 1001 Binary combinations 1010 through 1111 are not used (185) 10 = (000110000101) BCD = (10111001) 2 BCD needs more bits than its equivalent binary representation BCD is more readable than binary representation Prof. Wangrok Oh(CNU) Binary Codes 33 / 51

from a previous less significant pair of digits. Since each digit does not exceed 9, the sum cannot be greater than 9 + 9 + 1 = 19, with the 1 being a previous carry. Suppose we add the BCD digits as if they were binary numbers. Then the binary sum will produce a result in the range from 0 to 19. In binary, this range will be from 0000 to 10011, but in BCD, it is from 0000 to 1 1001, with the first (i.e., leftmost) 1 being a carry and the next four bits being the BCD sum. When the binary sum is equal to or less than 1001 (without a carry), the corresponding BCD digit is correct. However, when BCD the Addition binary sum is greater than or equal to 1010, the result is an invalid BCD digit. The When addition the sum of 6 = is equal (0110) to 2 to orthe less binary than sum 1001converts BCDit digit to the iscorrect digit and also produces When the a carry sumas is required. greater than This or is equal because to 1010 a carry in the most significant bit position of The the binary result isum an and invalid a decimal BCD carry differ by 16-10 = 6. Consider the following three The addition BCD additions: of 6 to the sum converts it to the correct BCD Binary Codes 4 0100 4 0100 8 1000 +5 +0101 +8 +1000 +9 1001 9 1001 12 1100 17 10001 +0110 +0110 10010 10111 In each This case, is the because two BCD a carry digits inare theadded mostas significant if they were bit two position binary of numbers. the If the binary sum binary is greater sum and than a or decimal equal to carry 1010, differ we add by 16 0110 10 to obtain = 6 the correct BCD sum and a carry. In the first example, the sum is equal to 9 and is the correct BCD sum. In the second example, the binary sum produces an invalid BCD digit. The addition of 0110 produces the correct BCD sum, 0010 (i.e., the number 2), and a carry. In the third example, the binary sum produces a carry. This condition occurs when the sum is greater than or equal to 16. Although the other four bits are less than 1001, the binary sum Prof. Wangrok Oh(CNU) Binary Codes 34 / 51

Binary Codes Section 1.7 Binary Codes 21 Th e a d d i t i o n o f t w o n digit unsigned BCD numbers follows the same procedure. Consider Addition the addition of two of n-digit 184 + BCD 576 = numbers 760 in BCD: Decimal Arithmetic BCD 1 1 0001 1000 0100 184 +0101 0111 0110 +576 Binary sum 0111 10000 1010 Add 6 0110 0110 BCD sum 0111 0110 0000 760 The first, least significant pair of BCD digits produces a BCD digit sum of 0000 and a carry for the next pair of digits. The second pair of BCD digits plus a previous carry Signed decimal numbers in BCD is similar to the signed binary produces a digit sum of 0110 and a carry for the next pair of digits. The third pair of number digits plus a carry produces a binary sum of 0111 and does not require a correction. A plus with four 0 s (0000) and a minus with 9 (1001) The signed-magnitude system is seldom used in computers Decimal Arithmetic The signed-complement system can be either the 9 s or the 10 s The representation complement of signed decimal numbers in BCD is similar to the representation of signed 10 s numbers complement in binary. We is the can one use most either often the familiar used signed magnitude system or the Addition signed complement system. The sign of a decimal number is usually represented with four bits to conform to the four bit code of the decimal digits. It is customary to 1 Summing all digits including the sign digit designate a plus with four 0 s and a minus with the BCD equivalent of 9, which is 1001. 2 Discarding the end carry The signed magnitude system is seldom used in computers. The signed complement system can be either the 9 s or the 10 s complement, but the 10 s complement is the one most often used. To obtain the 10 s complement of a BCD number, we first take the 9 s Prof. Wangrok Oh(CNU) Binary Codes 35 / 51

Binary Codes lated from the subtraction of each digit from 9. Th e p ro c e d u re s d e v e l o p e d f o r t h e s i g n e d 2 s complement system in the previous section also apply to the signed 10 s complement system for decimal numbers. Addition is done by summing all digits, including the sign digit, and discarding the end carry. This operation assumes that all negative numbers are in 10 s complement form. Consider the addition (+375) + (-240) = +135, done in the signed complement system: 0 375 +9 760 0 135 The Subtraction 9 in the leftmost position of the second number represents a minus, and 9760 is the 10 s complement of 0240. The two numbers are added and the end carry is discarded to 1 Take obtain the +135. 10 s Of complement course, the decimal of the subtrahend numbers inside the computer, including the sign 2 digits, Add it must to the be minuend in BCD. The addition is done with BCD digits as described previously. The subtraction of decimal numbers, either unsigned or in the signed 10 s complement system, Binary is the codes same as for in decimal the binary digits case: Take require the 10 s a minimum complement of of four the bits subtrahend per and add digit it to the minuend. Many computers have special hardware to perform arithmetic Many different codes can be formulated by arranging four bits into 10 distinct combinations Each code uses only 10 out of a possible 16 bit combinations that can be arranged with four bits The other six unused combinations have no meaning and should be avoided Other Decimal Codes Prof. Wangrok Oh(CNU) Binary Codes 36 / 51

Binary Codes Table 1.5 Four Different Binary Codes for the Decimal Digits Decimal Digit BCD 8421 2421 Excess 3 8, 4, 2, 1 0 0000 0000 0011 0000 1 0001 0001 0100 0111 2 0010 0010 0101 0110 3 0011 0011 0110 0101 4 0100 0100 0111 0100 5 0101 1011 1000 1011 6 0110 1100 1001 1010 7 0111 1101 1010 1001 8 1000 1110 1011 1000 9 1001 1111 1100 1111 1010 0101 0000 0001 Unused 1011 0110 0001 0010 bit 1100 0111 0010 0011 combi- 1101 1000 1101 1100 nations 1110 1001 1110 1101 1111 1010 1111 1110 BCD and the 2421 code are examples of weighted codes In a weighted code, each bit position is assigned a weighting factor BCD code has weights of 8, 4, 2 and 1 2421 code has weights of 2, 4, 2 and 1 (0110) BCD = 0 8 + 1 4 + 1 2 + 0 1 = 6 (1101) 2421 = 1 2 + 1 4 + 0 2 + 1 1 = 7 Prof. Wangrok Oh(CNU) Binary Codes 37 / 51

Binary Codes Note that some digits can be coded in two possible ways in the 2421 code: 4 = (0100) 2421 = (1010) 2421 2421 and excess-3 codes are examples of self-complementing codes 9 s complement of a decimal number is obtained directly by changing 1 s to 0 s and 0 s to 1 s (395) 10 = (011011001000) Excess-3 (604) 10 = (100100110111) Excess-3 The excess-3 code has been used in some older computers because of its self-complementing property Excess-3 is an unweighted code in which each coded combination is obtained from the corresponding binary value plus 3 The 8, 4, - 2, - 1 code is an example of assigning both positive and negative weights to a decimal code (0110) 8,4, 2, 1 = 0 8 + 1 4 + 1 ( 2) + 0 ( 1) = 2 Prof. Wangrok Oh(CNU) Binary Codes 38 / 51

Binary Codes Gray Code 24 Chapter 1 Digital Systems and Binary Numbers Only one bit in the code group changes in going from one number to the next Table 1.6 Gray Code Gray Code Decimal Equivalent 0000 0 0001 1 0011 2 0010 3 0110 4 0111 5 0101 6 0100 7 1100 8 1101 9 1111 10 1110 11 1010 12 1011 13 1001 14 1000 15 Gray code cannot be used in arithmetic circuits ASCII Character It is quite Code difficult to translate from decimal numbers to the Gray code and back to decimal again M a n y a p p l i c a t i o n s o f d i g i t a l c o m p u t e r s re q u i re t h e h a n d l i n g n o t o n l y o f n u m b e r s, b u t also of other characters or symbols, such as the letters of the alphabet. For instance, consider a high tech company with thousands of employees. To represent the names Prof. Wangrok Oh(CNU) Binary Codes 39 / 51

Gray Code Binary Codes Generation of Gray code Gray code for n bits can be generated recursively by prefixing a binary 0 to the Gray code for n-1 bits, then prefixing a binary 1 to the reflected Generation of Gray code: I 1 Copy 2 Mirroring 3 Prepending 0 s and 1 s 0 1 0 1 1 0 00 01 11 10 00 01 11 10 10 11 01 00 000 001 011 010 110 111 101 100 Generation of Gray code: II Div. Electrical and Computer Engineering Chungnam 1 National Start University from binary notation 14 2 Copy the MSB 3 Perform exclusive-or between two adjacent bits from right to left (13) 10 = (1101) 2 (1011) Gray Prof. Wangrok Oh(CNU) Binary Codes 40 / 51

Binary Codes Applications of Gray code 1 Optical Shaft Prof. Wangrok Oh(CNU) Binary Codes 41 / 51

Binary Codes Gray Code 27244 Digital Systems DesignProf. Wan Gray codes are also used in labeling the axes of Karnau maps 2 Labelling the axes of Karnaugh maps CD AB 00 01 11 10 00 01 11 1 1 1 1 10 Y=BD Div. Electrical and Computer Engineering Chungnam National University Prof. Wangrok Oh(CNU) Binary Codes 42 / 51

Binary Codes 3 Signal constellation mapping for digital modulation Prof. Wangrok Oh(CNU) Binary Codes 43 / 51

Binary Codes ASCII Character Code Many applications of digital computers require to handle characters or symbols The standard binary code for the alphanumeric characters is the American Standard Code for Information Interchange (ASCII) Seven bits to code 128 characters Refer to Table 1.7 for ASCII code table Extended ASCII is also very popular IBM ASCII 8-bit code (256 symbols) Including standard ASCII characters and the additional graphics and math symbols Prof. Wangrok Oh(CNU) Binary Codes 44 / 51

Binary Codes AS C I I i s a s e v e n bit code, but most computers manipulate an eight bit quantity as a single unit called a byte. Therefore, ASCII characters most often are stored one per byte. The extra bit is sometimes used for other purposes, depending on the application. For example, 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 to 1 are used for other symbols, such as the Greek alphabet or italic type font. Error Detecting Detecting Code Code To detect errors in data communication and processing, an eighth bit is sometimes added to the ASCII character to indicate its parity A parity bit is an extra bit included with a message to make the total characters number and oftheir 1 s even either and even odd or parity: odd To detect errors in data communication and processing, an eighth bit is sometimes added to the ASCII character to indicate its parity. A parity bit is an extra bit included with a message to make the total number of 1 s either even or odd. Consider the following two With even parity With odd parity ASCII A = 1000001 01000001 11000001 ASCII T = 1010100 11010100 01010100 In each Thecase, parity we bit insert is helpful an extra inbit detecting the leftmost errors position duringof the transmission code to produce of an even information number of 1 s from in the one character location for to even another parity or an odd number of 1 s in the character for odd parity. In general, one or the other parity is adopted, with even parity being more common. The parity bit is helpful in detecting errors during the transmission of information from one location to another. This function is handled by generating an even parity bit at the sending end for each character. The eight bit characters that include parity bits are transmitted to their destination. The parity of each character is then checked at the receiving end. If the parity of the received character is not even, then at least one bit has changed value during the transmission. This method detects one, three, or any odd com- Prof. Wangrok Oh(CNU) Binary Codes 45 / 51

Binary Storage and Registers A binary cell is a device that possesses two stable states and is capable of storing one bit (0 or 1) of information Register A register is a group of binary cells A register with n cells can store any discrete quantity of information that contains n bits (2 n states) Register transfer A digital system is characterized by its registers and the components that perform data processing In digital systems, a register transfer operation is a basic operation transferring of binary information from one set of registers into another set of registers The transfer may be direct from one register to another or may pass through data processing circuits to perform an operation Prof. Wangrok Oh(CNU) Binary Storage and Registers 46 / 51

new eight bit code when the keyboard is struck again. Each eight bit character transferred the processor register preceded by a shift of the previous character to the next eight Binary Storage cells on its and left. When Registers a transfer of four characters is completed, the processor register is full, and its contents are transferred into a memory register. The content stored in the MEMORY UNIT J O H N 01001010010011111100100011001110 Memory Register PROCESSOR UNIT 8 cells 8 cells 8 cells 8 cells Processor Register INPUT UNIT 8 cells Input Register Keyboard J O H N CONTROL FIGURE 1.1 Transfer of information among registers Prof. Wangrok Oh(CNU) Binary Storage and Registers 47 / 51

Binary Storage and Registers To process discrete quantities of information in binary form, a computer must be provided with devices that hold the data to be processed and with circuit elements that manipulate individual bits of information The device most commonly used for holding data is a register Prof. Wangrok Oh(CNU) Binary Storage and Registers 48 / 51

Binary Logic Binary logic: binary variables + set of logical operations There are three basic logical operations 1 AND 2 OR 3 NOT Table 1.8 Truth Tables of Logical Operations AND OR NOT x y x # y x y x + y x x 0 0 0 0 0 0 0 1 0 1 0 0 1 1 1 0 1 0 0 1 0 1 1 1 1 1 1 1 Section 1.9 Binary Logic 31 Each operation produces a binary result AND and OR are the same as those used for multiplication and addition. However, binary logic should not be confused with binary arithmetic. One should realize that an arithmetic variable designates a number that may consist of many digits. A logic variable is always either 1 or 0. For example, in binary arithmetic, we have 1 + 1 = 10 (read one plus one is equal to 2 ), whereas in binary logic, we have 1 + 1 = 1 (read one OR one is equal to one ). Prof. Wangrok Oh(CNU) Binary Logic 49 / 51

Binary Logic Logic Gates Logic gates are electronic circuits that operate on one or more input signals to produce an output signal Electrical signals such as voltages or currents exist as analog signals having values over a given continuous range In a digital system, these quantities are interpreted to be either of two recognizable values: 0 or 1 The intermediate region between the allowed regions is crossed only during a state transition Prof. Wangrok Oh(CNU) Binary Logic 50 / 51

Binary Logic 32 32 Chapter Chapter 1 1 Digital Digital Systems Systems and and Binary Numbers Volts Volts 3 3 0 FIGURE 1.3 Signal levels for binary logic 0 values FIGURE 1.3 Signal levels for binary logic values 2 Transition occurs between these limits Transition occurs between these limits 1 1 2 Signal range Signal for range logic 1for logic 1 Signal range for logic Signal 0 range for logic 0 The graphic symbols used to designate the three types of gates x y z x y x y z x y x (a) Two-input AND z x gate y x (b) Two-input OR z gate x y (c) NOT gate or inverter x x FIGURE y 1.4 y Symbols for digital logic circuits (a) Two-input AND gate (b) Two-input OR gate (c) NOT gate or inverter Prof. Wangrok Oh(CNU) Binary Logic 51 / 51 x x