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

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

Digital Fundamentals

CHW 261: Logic Design

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

Chapter 1 Review of Number Systems

Review of Number Systems

Digital Systems and Binary Numbers

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

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

NUMBER SYSTEMS AND CODES

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

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

MACHINE LEVEL REPRESENTATION OF DATA

Lecture (02) Operations on numbering systems

Numbering systems. Dr Abu Arqoub

CHAPTER 2 (b) : AND CODES

Chapter 2: Number Systems

Binary Codes. Dr. Mudathir A. Fagiri

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

Lecture 2: Number Systems

Digital Fundamentals

Korea University of Technology and Education

Computer Organization

Binary Systems and Codes

Introduction to Numbering Systems

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

SE311: Design of Digital Systems

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

Number System. Introduction. Decimal Numbers

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

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

Digital Systems and Binary Numbers

Number representations

UNIT 2 NUMBER SYSTEM AND PROGRAMMING LANGUAGES

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

Number Systems CHAPTER Positional Number Systems

DIGITAL SYSTEM DESIGN

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

TOPIC: NUMBER SYSTEMS

Number Systems Base r

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

COE 202- Digital Logic. Number Systems II. Dr. Abdulaziz Y. Barnawi COE Department KFUPM. January 23, Abdulaziz Barnawi. COE 202 Logic Design

CHAPTER V NUMBER SYSTEMS AND ARITHMETIC

Positional Number System

Lecture (03) Binary Codes Registers and Logic Gates

CMPE223/CMSE222 Digital Logic Design. Positional representation

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

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

in this web service Cambridge University Press

CPE 323 REVIEW DATA TYPES AND NUMBER REPRESENTATIONS IN MODERN COMPUTERS

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

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

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

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

CPE 323 REVIEW DATA TYPES AND NUMBER REPRESENTATIONS IN MODERN COMPUTERS

plc numbers Encoded values; BCD and ASCII Error detection; parity, gray code and checksums

10.1. Unit 10. Signed Representation Systems Binary Arithmetic

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

MC1601 Computer Organization

Digital Fundamentals

Chapter 2. Data Representation in Computer Systems

1.3 Systems of numeration: To represent quantities in the different systems of numeration, specific symbols are used, which are also called ciphers.

CMPS 10 Introduction to Computer Science Lecture Notes

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

Chapter 1. Digital Systems and Binary Numbers

Module -10. Encoder. Table of Contents

LOGIC DESIGN. Dr. Mahmoud Abo_elfetouh

Lecture 1: Digital Systems and Number Systems

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

Hybrid Electronics Laboratory

Fundamentals of Programming (C)

Module 2: Computer Arithmetic

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

Digital Logic Lecture 2 Number Systems

Number Systems and Binary Arithmetic. Quantitative Analysis II Professor Bob Orr

Objectives. Connecting with Computer Science 2

COPYRIGHTED MATERIAL. Number Systems. 1.1 Analogue Versus Digital

COMP Overview of Tutorial #2

Data Representation and Binary Arithmetic. Lecture 2

Digital Systems and Binary Numbers

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

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

Switching Circuits and Logic Design Prof. Indranil Sengupta Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

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.

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

Binary. Hexadecimal BINARY CODED DECIMAL

1. NUMBER SYSTEMS USED IN COMPUTING: THE BINARY NUMBER SYSTEM

Chapter 3 DATA REPRESENTATION

Computer Logical Organization Tutorial

Module 1: Information Representation I -- Number Systems

Microcomputers. Outline. Number Systems and Digital Logic Review

This tutorial gives a complete understanding on Computer Logical Organization starting from basic computer overview till its advanced architecture.

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

EEM 232 Digital System I

Semester Transition Point. EE 109 Unit 11 Binary Arithmetic. Binary Arithmetic ARITHMETIC

SCHOOL OF ENGINEERING & BUILT ENVIRONMENT. Mathematics. Numbers & Number Systems

Chapter 2 Data Representations

CS & IT Conversions. Magnitude 10,000 1,

Chapter 5: Computer Arithmetic. In this chapter you will learn about:

Number Systems & Encoding

Transcription:

Ms Sandhya Rani Dash UNIT 2: NUMBER SYSTEM AND CODES Structure 2.1 Introduction 2.2 Objectives 2.3 Binary Numbers 2.3.1 Binary-to-Decimal conversion 2.3.2 Decimal-to-Binary Conversion 2.4 Octal Numbers 2.4.1 Octal-to-Binary Conversion 2.4.2 Binary-to-Octal Conversion 2.4.3 Octal-to-Decimal Conversion 2.4.4 Decimal-to-Octal conversion 2.5 Hexadecimal Numbers 2.5.1 Hexadecimal-to-Binary Conversion 2.5.2 Binary-to-Hexadecimal Conversion 2.5.3 Hexadecimal-to-Decimal Conversion 2.5.4 Decimal-to-Hexadecimal Conversion 2.5.5 Octal to Hexadecimal Conversion 2.5.6 Hexadecimal to Octal Conversion 2.6 Arithmetic Operation 2.7 1 s and 2 s Complement 2.7.1 Subtraction using 1 s complement 2.7.2 Subtraction using 2 s complement 2.8 9 s and 10 s Complement 2.8.1 Subtraction using 9,s complement 2.8.2 Subtraction using 10 s complement 2.9 Codes 2.9.1 BCD code 2.9.2 Excess-3 code 2.9.3 Gray code 2.10 Unit Summary 1.1 Introduction The study of number system begins with the familiar decimal number system. The decimal number system consists of ten unique digits 0 to 9. So, its base/radix is 10 (since it involves with 10 symbols).the digits 0 to 9 are used to specify any number. Computers and other digital circuits don t process decimal numbers. They work with binary numbers which consists of only two digits 0&1.This creates a problem. Because to represent larger decimal quantities, a very long binary number is required. So to compress this long string of binary numbers, octal & hexadecimal number systems are widely used in digital systems.so the knowledge of these number systems is very essential for understanding, analyzing and designing of digital systems.

This unit discuss about the decimal, binary, octal and hexadecimal numbers. The inter conversion of these number systems are also explained here. Different types of codes, which are commonly used in digital systems and microprocessors have also been discussed in this unit. 1.2 Objectives After going through this unit you will be able to: i) Explain different types of number system (Binary, Decimal, and Octal & Hexadecimal) ii) Convert one number system to another iii) Appreciate binary arithmetic operation iv) Define complements (1 s, 2 s, 9 s & 10 s complement) v) Apply use of complements in subtraction vi) Explain different types of codes and convert a code to binary and vice versa. 2.3 Binary Numbers Binary number system is extensively used in digital electronics since it uses only one two symbols 1 & 0. These two digits represent the two voltage levels high or low in digital electronics. The base (radix) of the binary number system is 2. It is a positional system, i.e., every position is assigned a specific weight. In digital system each binary digit is called a bit A group of 4 bit is called nibble A group of 8 bit is called byte

Representation of Decimal and Binary numbers The following table represents the decimal number and its corresponding binary number Decimal Number Binary Number B3 B2 B1 B0 0 0 0 0 0 1 0 0 0 1 2 0 0 1 0 3 0 0 1 1 4 0 1 0 0 5 0 1 0 1 6 0 1` 1 0 7 0 1 1 1 8 1 0 0 0 9 1 0 0 1 2.3.1 Binary to decimal conversion Binary numbers can be converted into a decimal number by multiplying by the binary numbers 1 or 0 by their positional weight and adding the product. Convert the binary number 11010 to its decimal equivalent Binary Number 11010 Conversation of Binary to decimal 1x2 4 +1x2 3 +0x2 2 +1x2 1 +0x2 0 =16+8+0+2+0 =26 Decimal Equivalent 26 2.3.2 Decimal to Binary conversion Any decimal numbers can be converted into its equivalent binary numbers by successive division by 2 and keeping the track of the reminders. The division is continued till the quotient is 0. The number read from bottom to top gives the equivalent binary number.

For example Convert 26 to its binary equivalent Decimal Number Quotient Remainder Binary Equivalent 26/2 13 0-MSB (26) 10 13/2 6 1 6/2 3 0 3/2 1 1 1/2 0 1-LSB (11010) The decimal fraction is converted to binary fraction by successive multiplication by 2 and keeping the track of integers generated. The multiplication is continuities till the fraction part of the product is 0. The integers read from top to bottom to get the binary equivalent. For example Convert 0.625 to its binary equivalent Decimal Number 0.625 Generated Integer 0.625x 2 1.250 1-MSB 0.250x 2 0.500 0 0.500x 2 1.000 1- LSB 0.000x 2 0.000 0 Binary Equivalent 0.101

Self Check Exercise-1 A. For Q No. 1-5 select the most appropriate alternative from among the four alternatives given below each question 1. The digital systems usually operate on system. a) Binary b) decimalc) octal d) hexadecimal 2. The binary system uses power of for positional values. a) 2 b) 8 c) 16 d) 10 3. After counting 0, 1, 10, 11, the next binary number is a) 12 b) 100 c) 101 d) 110 4. The number 1000 is equivalent to decimal number a) one thousand b) eight c) four d) sixteen 5. In binary numbers, shifting the binary point one place to the right a) Multiplies by 2 b) divides by 2 c) Decreases by 2 d) increases by 10 B. Answer the following questions 6. Convert the following decimal numbers to their binary equivalents: a) 167 b) 72.45 c) 52 d) 163.875 7. How do you convert a decimal number to an equivalent number in any other base system? 2.4 Octal Numbers The base or( radix) of the octal number system is 8.This number system uses 8 different symbols 0,1,2,3,4,5,6,7. Each significant position in an octal no. system has a positional weight. These weights are given in the ascending powers of 8, i.e 8 0, 8 1, 8 2,.etc. respectively. The binary equivalent of an octal no. must be a group of 3 bits word, since the base of octal no. system is 8=2 3.

2.4.1Octal to Binary conversion Octal numbers can be converted into equivalent binary numbers by replacing each octal digit by its 3 bit equivalent binary. Example: convert (3702) 8 to a binary number. (3702) 8 = 3 7 0 2 011 111 000 010 The number (3702) 8 = (011111000010) 2 = (11111000010) 2 On the most significant digit, leading zeros can be suppressed.i.e. 3 can be written as 11 instead of 011. 2.4.2Binary to octal conversion To convert from binary to octal back, the reverse procedure is used.i.e. divide the whole binary string into groups of 3 bits. Then starting from LSB and moving towards MSB, convert each group of 3 bits into the corresponding octal digit. Convert (10101011111) 2 to an octal number. Solution: 10 101 011 111 2 5 3 7 Therefore (10101011111) 2 = (2537) 8 2.4.3 Octal to decimal conversion Any octal number can be converted into its equivalent decimal number by multiplying each digit of the octal number by the weight of its position and then adding the products. Example Convert (4257.14) 8 into its equivalent decimal number. Solution (4257.14) 8 =4 x8 3 +2 x8 2 + 5 x 8 1 +7 x8 0 + 1 x 8-1 +4 x 8-2

=2048 + 128 + 40 + 0.125 + 0.0625 = (2216.1875) 10 2.5.4 Decimal to octal conversion The octal equivalent of a decimal no. can be obtained by dividing a given decimal number by 8 repeatedly until a quotient 0 is obtained. The process is exactly the same as the method explained earlier. The following example illustrates the conversion from decimal to octal. Convert (115.1875) 10 to octal no. Integer Part Quotient Reminder Octal Equivalent 115/8 14 3 MSB 115 14/8 1 6 (163) 8 1/8 0 1 LSB Fractional Part (0.1875) 10 Result Integral Part Octal Equivalent 0.1875x8 1.5000 1 0.5000x8 4.000 4 (0.14) 8 Therefore (115.1875) 10 = (163.14) 8 Self Check Exercise 2 A. For Q No. 8-11 select the most appropriate alternative from among the four alternatives given below each question 8. The number 12 8 is equivalent to decimal a) 12 b) 20 c) 10 d) 4 9. The number 1000101 2 is equivalent to octal a) 54 b) 45 c) 37 d) 25 10. The number 17 8 is equivalent to binary a) 11 b) 1110 c) 10000 d) 1111

11. Which of the following is NOT an octal number? a) 19 b) 77 c) 15 d) 101 B. Answer the following questions 12. Convert each of the octal numbers to binary. a)15 8 b) 173 8 c) 367.52 8 d) 157 8 13. Convert the following decimal no. to octal no. then to binary. a)59 b) 0.58 c) 64.2 d) 199.3 2.5 Hexadecimal Numbers The hexadecimal number system is the most popular means of direct data entry and retrieval in digital system. The base of hexadecimal number system is 16 and uses 16 symbols, namely, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, and F. The symbol A to F represents the decimal 10 to 15 respectively. Since its base is 16= 2 4, every 4 bit binary digit combination can be represented by one hexadecimal digit. Each significant position in an hexadecimal number has a positional weight. These weights are given in the ascending powers of 16. i.e., 16 0, 16 1, 16 2,. etc 2.5.1 Hexadecimal-to-binary conversion The conversion of Hexadecimal to Binary is the reverse process of conversion from Binary to Hexadecimal as explained above. i.e. each hexdigit is replaced by its 4-bit binary group. For example Convert (2DAC) 16 to Binary (2DAC) 16 = 2 D A C 0010 1101 1010 1100 = (10110110101100) 2

2.5.2 Binary to hexadecimal conversion To convert a binary no. to a hexadecimal no., divide the whole binary string in to groups of 4 bits each and then replace each 4 bit group by the equivalent hexadecimal digit For example Convert (1010100100) 2 to hexadecimal no. (1010100100) 2 = 0010 1010 0100 = 2 A 4 = (2A4) 16 2.5.3 Hexadecimal to decimal conversion To Convert a Hexadecimal number to Decimal multiply each digit in the Hex no. by its position weight and take the summation of all these product terms Convert to (5A6) 16 to Decimal (5A6) 16 = 5 x 16 2 + 10 x 16 1 + 6 x 16 0 = 1280 + 160 + 6 = (1446) 10 2.5.4 Decimal to hexadecimal conversion A decimal no. can be converted to Hexadecimal no. by successively dividing the given decimal no. by 16 till the quotient is 0. Convert (2598) 10 to Hexadecimal Decimal Number (2598) 10 Quotient Remainder in Decimal Hexadecimal No. 2898/16 162 6 6 162/16 10 2 2 10/16 0 10 A Hexadecimal Equivalent (A326) 16 Therefore (2598) 10 = (A326) 16

2.5.5 Octal to hexadecimal conversion To convert an octal no. to hexadecimal the easiest method is to first convert the hex no. to its binary equivalent and then the binary no. to hexadecimal. It will be clear from the example given below. : Convert (756.402) 8 to hexadecimal no. (756.402) 8 = 7 5 6. 4 0 2 = 111 101 110 100 000 010 For the integer part, group the binary bits into 4 from LSB to MSB and for the fractional part group the bits from the MSB to LSB (756.402) 8 = 0001 1110 1110. 1000 0001 000 = 1 E E 8 1 0 = (1EE.810) 16 2.5.6 Hexadecimal to octal conversion To convert a hexadecimal no. to octal, the simple way is to first convert binary no. to octal. : Convert (56) 16 to Octal no. (56) 16 = 0101 0110 = (01010110) 2 = 01 010 110 = 1 2 6 = (126) 8 Self Check Exercise 3 A. For Q No. 14-19, Select the most appropriate alternative from among the four alternatives given below each question 14. The radix/base of the hexadecimal no. system is a)10 b)16 c) 8 d) 2 15. The symbol E represents the decimal a)13 b)15 c) 14 d) 12 16. The number 2D 16 is equivalent to binary

a) 0010 1101 b) 1101 0010 c) 0011 1101 d) 010 0011 17. Hexadecimal number system is used as a shorthand language for representing numbers. a) decimal b)binary c) octal d) large 18.The binary equivalent of A 16 is a)1010 b) 1011 c) 1000 d) 1110 19. The number 47 16 is equivalent to octal a) 701 b) 137 c) 401 d) 107 B. Answer the following questions 20. What are the advantages of a a) Binary no. system b) Hexadecimal no. system 21. Convert the following hexadecimal numbers to binary. a) 49 16 b) 324 16 c) 4BAC 16 d) 3A9.BD 16 2.6 Arithmetic Operation Binary arithmetic is much simpler than decimal arithmetic because here only two digits 0&1 are involved. Arithmetic operations in a computer are done in its arithmetic unit by using binary numbers. The basic arithmetic operations are, addition,subtraction, multiplication,division. These operations are performed by digital logic circuits called the adder, sub tractor, multiplier and divider. The arithmetic rules for Addition, Subtraction, Multiplication, and Division of binary numbers are given below. Addition Subtraction Multiplication Division 0+0=0 0-0=0 0 x 0=0 0/1=0 0+1=1 1-0=0 0 x 1=0 1/1=1 1+0=1 1-1=0 1 x 0=0 0/0=0 1+1=10 10-1=1 1 x 1=1 1/0=not allowed

Self Check exercise 4 A. For Q No. 22-26 Select the most appropriate alternative from among the four alternatives given below each question 22. The binary addition 1 + 1 + 1 gives a) 111 b) 10 c) 110 d) 11 23. The cumulative addition of the four binary bits ( 1 + 1 + 1 + 1 ) gives a) 1111 b) 111 c) 100 d) 1001 24. The result of binary subtraction (100 011) is a) 111 c) 111 c) 011 d)001 25. The result of binary multiplication 111 2 x 102 is a) 1101 b) 0110 c) 1001 d) 1110 26.The binary division 11000 2 /100 2 gives a) 110 b) 1100 c) 11 d) 101 B. Answer the following questions 27. Subtract the following groups of binary numbers. a) 11110 11011 b) 10110.1-1100.01 c) 101.101 100.1 28. Add the following groups of binary numbers using the binary addition method. a) 1010 + 1011 b) 1011.0111 + 1101.101 c) 1110.1011 + 1001.1110 2.7 1 s and 2 s Complement There are two complement forms used in digital systems to represent signed numbers. These are 1 s complement and 2 s complement form. These two forms are used to represent negative numbers. Most digital computers do subtraction by the 2 s complement method.the advantage of performing subtraction by the complement method is reduction in the hardware. Instead of having separate digital circuits for addition and subtraction, only adding circuits are needed.i.e. subtraction is also performed by adders only. To take the 1 s complement of a binary no., simply change all 1 s to 0s and all 0 s to 1s

The 1 s complement of 110010 is 001101 Similarly the 2 s complement of a binary no. can be obtained by adding 1 to its 1 s complement Find the 2 s complement of 10110 1 s complement of 10110= 01001 For obtaining 2 s complement of 10110, you have to add 1 to 01001(1 s complement of 10110) i.e, 1+ 01001= 01010 2.7.1 Subtraction using 1 s complement The subtraction using 1 s complement can be obtained by the following methods: Take the 1 s complement of the subtrahend (smaller number). Add this to the minuend (larger number). If a carry is generated, it indicates that the answer is positive. Add the carry to the result. This carry is called the end-around carry (EAC). If no carry is generated, then the answer is negative. Take the 1 s complement of the original addition and change the sign. 1 Subtract (1011) 2 from (1110) 2 using 1 s complement method. 1 1 1 0 (+) 1 s complement- 0 1 0 0 Carry 1 0 0 1 0 Add Carry 1 0 0 1 1 The answer is (0011) 2

2 Subtract (11000) 2 from (101) 2 using 1 s complement method 1 0 1 (+) 1 s complement 0 0 1 1 1 No carry 0 1 1 0 0 The answer is ve, since no carry is obtained. Si the answer is the 1 s complement of the 01100 and is in opposite sign i.e, -10011 2.7.2 Subtraction using 2 s complement 2 s complement subtraction can be obtained by the following methods. Take the 2 s complement of the subtrahend (smaller number). Add it to the minuend (larger number). Presence of a Carry indicates that the answer is positive. Omit the carry. Absence of a carry indicates that the answer is negative. Take the 2 s complement of the original addition and change the sign. Subtract (1011) 2 from (1110) 2 using 2 s complement method 1 1 1 0 (+) 2 s complement 0 1 0 1 Carry 1 0 0 1 1 The carry is ignored. Thus the answer is (0011) 2 2 Subtract (10100 2 from (1000) 2 using 2 s complement method 1 0 0 0 (+) 2 s complement 0 1 1 0 No Carry 1 1 1 0 No carry is obtained. The answer is the 2 s complement of (1110) 2 and is in opposite sign. i.e, -(0010) 2

2.8 9 s and 10 s Complement 9 s complement The 9 s complement of a decimal number can be obtained by subtracting each digit in the number from 9,i.e a digit plus its 9 s complement equals to 9. The 9 s complement of decimal digits 0 to 9 are listed below. Decimal No. 9 s Complement 0 0 1 8 2 7 3 6 4 5 5 4 6 3 7 2 8 1 9 0 Find the 9 scomplement of each of the following decimal no.s a) 15 b)135 Subtract each digit in the no. from 9 to get the 9 s complement a) 99 15 = 84 (9 s complement of 15) b) 999 135 = 864 (9 s complement of 135) 10 s complement The 10 s complement of a decimal no. i equal to its 9 s complement + 1 Convert the following decimal no. in to its 10 s complement form a) 18 b) 152 a) 99-18= 81 (9 s complement of 18) 81+1= 82(10 s complement of 18) b) 999-152= 847 (9 s complement of 152) 847+1 = 848 (10 s complement of 152)

2.8.1 Subtraction using 9 s complement Subtraction of a smaller number from a larger number using 9 s complement Steps: Take the 9 s complement of the smaller number Add the 9 s complement to the larger number Carry indicates that the answer is positive. Add the carry to the list significant digit If there is no carry the answer is negative. Take the 9 s complement of the result and change the sign Subtract 143 from 363 using 9 s complement Direction Subtraction 9 s complement subtraction 363 363-143 9 s complement of 143 + 856 220 Carry 1 219 Add carry to the result 1+ 219= 220 The answer is positive. i.e, 220 Subtract 745 from 245 using 9 s complement Direction Subtraction 9 s complement subtraction 245 245-745 9 s complement of 745 + 254-500 Carry 0 499 9 s complement of 499 = 999-499= 500 No carry indicates that the answer is negative. i.e, -500

2.8.2 Subtraction using 10 s complement It is analogous to the often used 2 s complement method in binary subtraction. In this method the minuend is added to the 10 s complement of the subtrahend and the carry is ignored. a) Subtract 54 from 88 using 10 s complement method Direction Subtraction 10 s complement subtraction 88 88-54 10 s complement of 54 + 46 34 Carry 1 34 Ignore the carry. The answer is positive i.e, 34 b) Subtract 813 from 432 using 10 s complement method Direction Subtraction 10 s complement subtraction 432 432-813 10 s complement of 813 + 187-381 Carry 0 619 10 s complement of 619 = 381 Since there is no carry, the answer is negative. i.e, -381 Self Check Exercise 5 A. For Q No. 29-33 select the most appropriate alternative from among the four alternatives given below each question 29. The chief reason why digital computers use complemental subtraction is that it a) Simplifies their circuitry b) is a very simple process c) can handle negative numbers easily. d) Avoids direct subtraction 30. The 1 s complement of 1010 2 is a) 0110 b) 0101 c) 1110 d) 0011

31. The 2 s complement of 1000 2 is a) 0111 b) 0101 c) 1000 d) 0001 32. The 9 s complement of 19 is a) 91 b) 99 c) 80 d) 81 33.The 10 s complement of 46 is a) 54 b) 53 c) 45 d) 35 B. Answer the following questions 34. How can negative no be represented? Distinguish between 1 s complement and 2 s complement 35.Distinguish between 9 s complement and 10 s complement? 2.9 Codes We are very comfortable with the decimal number system, but digital systems like computers & other digital circuits process the data in the binary format. So various binary codes are used to represent the data. A code is a symbolic representation of discrete information, which may be present in the form of numbers, letters or physical quantities. The information used in every code is represented in binary form. The binary code can be classified into two types of codes, i.e. numeric codes and alphanumeric codes. Alphanumeric codes represent alphanumeric information, i.e. letters of the alphabet, and decimal numbers as a sequence of 0s and 1s. An example of alphanumeric cod e is the ASCII code (American Standard Code for Information Interchange). Numeric code represents numeric information, i.e. only numbers as a series of 0s and 1s.An example of the numeric code is the Binary coded decimal (BCD) code which is used to represent decimal digits. Codes are also used for error detection and error correction purpose. Since when digital signals are transmitted from one location to another location, errors may occur due to electrical noise. Various types of codes are discussed below.

2.9.1 BCD (or) 8421 code A Binary Coded Decimal (BCD) is one in which, decimal digits are encoded by their natural binary equivalents-one at a time-into groups of four bits. For example (25) 10 is represented by [0010 0101] using BCD code, rather than (10001) 2. It is a positional weight code. Each position of a number represents a specific weight. These codes are also known as 8421 code or simply BCD code. The number 8421 indicates the binary weights of the four bits. i.e. the weights of the first (right most) position is 2 0 =1, 2 1 =2, 2 2 =4, 2 3 =8.Replacing from left to right, the weights are 8-4-2-1,and hence it is called 8421 code. The disadvantage of BCD code is that it requires more no. of bits to code a decimal number. But the ease of conversion between the BCD code to decimal number and vice versa is the main advantage of this code, which makes it useful and popular code for input,output operations in digital systems.to convert any decimal number in to BCD,each decimal digit should be replaced by the appropriate 4-bit code. The following table summarizes the binary and BCD codes for the decimal numbers 0 to 15. Decimal numbers Binary number Binary Coded Decimal(BCD) 0 0000 0000 1 0001 0001 2 0010 0010 3 0011 0011 4 0100 0100 5 0101 0101 6 0110 0110 7 0111 0111 8 1000 1000 9 1001 1001 10 1010 0001 0000

11 1011 0001 0001 12 1100 0001 0010 13 1101 0001 0011 14 1110 0001 0100 15 1111 0001 0101 Convert (3906) 10 to BCD. 3 9 0 6 11 1001 00000 0110 Therefore (3906) 10 =11100100000110 Note: Leafing zeros are added to ensure that each digit is represented by four bits.the leading zeros can be suppressed on the most significant digit. Conversion flow chart HEXADECIMAL BINARY DECIMAL OCTAL BCD The flow chart summarizes the conversions that have been discussed so far. There is no line directing from octal to BCD,because that direct conversion was not presented. To convert from octal to BCD, convert to binary, then decimal, then BCD. 2.9.2 Excess-3 code The XS-3 code is a non-weight code. This means each position with in a binary number isn t assigned affixed value. This code is a self complementing code, which

means 1 s complement of the coded number yields 9 s complement of the number itself. As the name indicates, XS-3 code represents a decimal number,in binary form, as a number greater than 3. An XS-3 code is obtained by adding 3 to a decimal number, then convert it into its equivalent BCD code. : A decimal 4 can be coded, by adding 3 into4; in order to obtain 7.7 is then encoded in its equivalent 4 bit binary code 0111. So 0111 is the XS-3 code of the decimal number 4. Or it can also be obtained directly in another way by adding binary equivalent of 3 to the natural BCD code of the digit. i.e. Decimal 4 is coded as 0100+0011=0111 in XS-3 code. Convert (463) 10 into its XS-3 code. Given decimal number 4 6 3 Add 3 to each bit +3 +3 +3 Sum 7 9 6 Converting the above sum into its BCD code, we have Sum 7 9 6 BCD 0111 1001 0110 Hence, the XS-3 code for (463) 10 is 0111 1001 0110 The following table summarizes the BCD, XS-3 code and 9 s complement representation for decimal digits. Decimal BCD code XS-3 code 9 s complement 0 0000 0011 1100 1 0001 0100 1011 2 0010 0101 1010 3 0011 0110 1001 4 0100 0111 1000 5 0101 1000 0111

6 0110 1001 0110 7 0111 1010 0101 8 1000 1011 0100 9 1001 1100 0011 2.9.3 Gray codes The gray code isn t a weighted code and isn t suitable for arithmetic operations, but finds application in input/output devices and in some types of analog to digital converters. Gray code is a cyclic code which has a special property of containing two successive code words differ in one bit position only, i.e. it is a unit distance code. It is also called as the reflected code. Conversion of a binary number to gray code Keep the first bit of the gray code is the same as the first bit of the binary number. The second bit of the gray code equals to the sum of first and second bit of the binary number. Discard the carry if it is generated from the sum. The third bit of the gray cod equals to the sum of second and third bit of the binary number and so on. Example: Convert the binary (110010) 2 to its gray code. Solution: 1 + 1 + 0 + 0 + 1 + 0 [Binary] 1 0 1 0 1 1 [Graycode] Conversion from gray code to binary Conversion of a Gray code into its binary form involves the reverse of the procedure as given below i) The first binary bit (MSB) is the same as that of the first Gray code bit ii) If the second Gray bit is zero, the second binary bit is the inverse of its first binary bit. iii) Step 2 is repeated for each successive bit

Convert [1010111] G to binary Solution: 1 0 1 0 1 1 1 Gray 1 1 0 0 1 0 1 Binary Therefore [1010111] G = [1100101] 2 Self Check Exercise 6 A. For Q No. 36-41 Select the most appropriate alternative from among the four alternatives given below each question 36. BCD code is a) non-weighted code b) the same thing as binary numbers c) a binary code d) an alphanumeric code 37. Which of the following 4-bit combinations is/are invalid in the BCD code? a) 1010 b) 0010 c) 0101 d) 1000 38. In XS-3 code each coded number is than in BCD a) four larger b) three smaller c) three larger d) much larger 39. The XS-3 code of 0101 2 is a) 1001 b) 1000 c) 1001 d) 0110 40. Gray code is a) non-weighted code b) weight code c) a binary code d) an alphanumeric code 41. The gray code of 0111 2 is a) 1000 b) 1001 c) 0101 d) 0100

B. Answer the following questions 42. What is a BCD code? What are its advantages and disadvantages? 43. Define the XS-3 code and gray code. Why these are important? 2.9 Unit Summary This unit explains the various number systems, which are widely used in digital systems. The general properties of number system, methods of conversion from one number system to another and the rules of arithmetic operations are discussed. Various complement methods like 1 s complement, 2 s complement, 9 s complement& 10 s complement are introduced to make the subtraction easier. With the application of these methods the subtraction can be achieved by adding the complement of the subtrahend to the minuend. Different codes are used in digital systems which may be in the form of numbers, letters or physical quantities. Some of the more commonly used codes like BCD, XS-3Code, gray code are introduced. The knowledge of these number systems & codes is very essential for the effective understanding of digital systems Answers to Check Your Progress 1. (a) 2. (a) 3. (b) 4. (b) 5. (a) 6. a)10100111 2 b) 1001000.01110 2 c) 110100 2 d) 10100011.111 2 7. A decimal number can be converted to an equivalent no. in any other base system with the base b by successively dividing the decimal no by b. In this method, the reminders are read from bottom to top. Similarly a decimal fraction can be converted to an equivalent no. in any other base system with the base b by successively multiplying the decimal no by b. In this method, the integers to the left of the radix point are read from top to bottom. 8). (c) 9. (b) 10. (d) 11. (a) 12. a) 0001 2 b) 001 111 011 2 c) 011 110 111.101 010 2 d) 001 101 111 2 13 a ) 1110112 b) 0. 100 101 000 111 2 c) 001 000 000.001 100 2 d) 011 000 111.010 011 001 2

14. (a) 15. (c) 16. (a) 17. (a) 18.(a) 19. (d) 20. The advantages of binary no. system is that, it is very simple, because it consists of only two digits, i.e.0&1. So it is useful in digital computers,since the switching circuits used in these computers use two state devices such as transistors,diodes etc. Hexadecimal no. systems are used to compress the long strings of binary numbers.it is the most popular means of direct data entry and retrieval in digital systems. 21. a ) 0100 1001 2 b) 0011 0010 0100 2 c) 0100 1011 1010 1100 2 d) 0011 1010 1001. 1011 1101 2 22. (d) 23. (c) 24. (d) 25. (d) 26. (a) 27.a) 0011 b) 1010.01 c) 1.001 28.a) 10101 b) 11001.0001 c) 11000.1001 29. (a) 30. (b) 31. (c) 32. (c) 33. (a) 34.Negative numbers can be represented in sign magnitude form,i.e. MSB represents the sign bit (0 for positive and 1 for negative) and the remaining bits represent the magnitude of the no. Negative numbers can also be represented by the 1 s complement form, or in 2 s complement form 1 s complement can be easily obtained using an inverter. The 2 s complement can be obtained by first obtaining the 1 s complement and then adding (1) to it 35. The 9 s complement of a decimal no. can be obtained by subtracting each digit of that decimal no. from 9. The 10 s complement of a decimal no. is obtained by adding a 1 to its 9 s complement. 36. (c) 37. (a) 38. (c) 39. (b) 40. (a) 41. (d) 42. The BCD code uses the binary no. system to specify the decimal numbers 0 to 9. In this code each decimal digit, 0 through 9 is coded by 4-bit binary no. It is also called as the 8421 code. The main advantage of this code is its ease of conversion to and from decimal and the disadvantage of this BCD code is that, arithmetic

operations are more complex then they are in pure binary. It is less efficient than the pure binary, in the sence that it requires more bits. 43. A XS-3 code is a BCD code formed by adding 3(0011) to the binary equivalent of the decimal no. A Gray code is one, in which only one bit changes between successive numbers. It is also called a unit distance code The XS-3 code helps in computing mathematical operations in digital computers. The Gray code is useful for its ease of conversion to and from binary. It is used in instrumentation and data acquisition systems where linear or angular displacement is measured. It is used in I/O devices, A/D converters and other peripheral devices. References Bignell, J and Donovan, R. (1989) Digital Electronics, Delmar Publishers Inc. New York Jain, R. P. (2007) Modern Digital Electronics; Third Edition; Tata McGraw-Hill Publishing Company Limited; New Delhi Kumar, A. A. (2004) Fundamentals of Digital Circuits; Seventh Edition; Eastern Economy Editions; Prentice- Hall India Pvt. Ltd; New Delhi Mano, M. M. (2006) digital Logic and Computer Design; Second Edition; Eastern Economy Editions; Prentice- Hall India Pvt. Ltd; New Delhi Malbert, A. B. and Leach, D. P. (1993) Digital Principles and Applications, Tata Mc Graw hill Publishing Company Limited, New Delhi Salivahanan, S. and Arivazhagan, S. (2006) Digital Circuits and Design, Vikas Publishing House Pvt Ltd, Delhi Srinivasan, P. (2007) National Programme Technology Enhanced Learning Video Lectures on Introduction to Digital Circuits and System. Lecture I & II

Unit End Exercise 1. State the common features between different number system. 2. What are meant by 1 s and 2 s complement of a binary number? 3. Explain the rules for binary subtraction using 1 s and 2 s complement methods. 4. Compare BCD and Binary systems of coding 5. How do you convert a binary number to a Gray number and vice versa.