ee 202 chapter 1 number and code system

81
EE202 EE202 EE202 EE202 DIGITAL ELECTRONICS DIGITAL ELECTRONICS DIGITAL ELECTRONICS DIGITAL ELECTRONICS BY: SITI SABARIAH SALIHIN BY: SITI SABARIAH SALIHIN BY: SITI SABARIAH SALIHIN BY: SITI SABARIAH SALIHIN CHAPTER 1: NUMBER AND CODE SYSTEMS [email protected] www.sabariahsalihin.com

Upload: ct-sabariah-salihin

Post on 29-Nov-2014

2.741 views

Category:

Education


1 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Ee 202 chapter 1 number and code system

EE202EE202EE202EE202DIGITAL ELECTRONICSDIGITAL ELECTRONICSDIGITAL ELECTRONICSDIGITAL ELECTRONICS

BY: SITI SABARIAH SALIHINBY: SITI SABARIAH SALIHINBY: SITI SABARIAH SALIHINBY: SITI SABARIAH SALIHIN

CHAPTER 1: NUMBER AND CODE SYSTEMS

[email protected] www.sabariahsalihin.com

Page 2: Ee 202 chapter 1 number and code system

Programme Learning Outcomes, PLOProgramme Learning Outcomes, PLOProgramme Learning Outcomes, PLOProgramme Learning Outcomes, PLOUpon completion of the programme, graduates should be able to:

� PLO 1 : Apply knowledge of mathematics, scince and engineering fundamentals to well defined electrical and electronic engineering procedures and practices

Course Learning Outcomes, CLOCourse Learning Outcomes, CLOCourse Learning Outcomes, CLOCourse Learning Outcomes, CLO� CLO 1 : Illustrate the knowledge of Digital Number Systems, codes and

logic operations correctly.

CHAPTER 1: NUMBER AND CODE SYSTEMS

EE202 DIGITAL ELECTRONICS

Page 3: Ee 202 chapter 1 number and code system

Upon completion of this Chapter, students should be able to:

� Know the following number system:decimal, binary, octal and Hexadecimal and convert the numbers from ne system to another.

� Understand Octal Number System.� Understande Hexadecimal Number System.� Understand how binary codes are used in computers

representing decimal digits, alphanumeric characters and symbols.

CHAPTER 1: NUMBER AND CODE SYSTEMS

EE202 DIGITAL ELECTRONICS

Page 4: Ee 202 chapter 1 number and code system

1.1INTRODUCTION

� Many number system are in use in digital technology. The Most common are the decimal, binary, octal and hexadecimal system.

� The Binary number system is the most important one in digital systems.

� The Decimal System is the most familiar because it is universally used to represent quantities outside a digital system and it is a tool that we use every day.

EE202 DIGITAL ELECTRONICS

Page 5: Ee 202 chapter 1 number and code system

� This means that there will be situations where decimal values have to be converted to binary values before they are entered into the digital system.

� For example, when you punch a decimal number into your hand calculator(or computer), the circuitry inside the device converts the decimal number to a binary value.

1.1 INTRODUCTION

EE202 DIGITAL ELECTRONICS

Page 6: Ee 202 chapter 1 number and code system

� Likewise, there will be situations where the binary values at the outputs of a digital circuit have to be converted to decimal values for presentation to the outside world.

� For example, your calculator (or computer) uses binary numbers to calculate answers to a prolem, then converts the answers to a decimal value before displaying them.

� The octal (base-8) and hexadecimal (based-16) number systems are both used for the same purpose-to provide an efficient means for representing large binary numbers.

1.1 INTRODUCTION

EE202 DIGITAL ELECTRONICS

Page 7: Ee 202 chapter 1 number and code system

� An understanding of the system operation requires the ability to convert from one number system to another.

� This chapter will show you how to perform these conversions .

� This chapter will also introduce some of the binary codes that are used to represent various kinds of information.

� These binary codes will used 1’s and 0’s .

1.1 INTRODUCTION

EE202 DIGITAL ELECTRONICS

Page 8: Ee 202 chapter 1 number and code system

1.1.1 Decimal Number System

� The Decimal System is composed of 10 numerals or symbols.

� These 10 symbols are 0,1,2,3,4,5,6,7,8,9 : using these symbols as digits of a number, we can express any quantity.

� The decimal system, also called the base-10 system because it has 10 digits, has evolved naturally as a result of the fact that man has 10 fingers.

� In fact, the word “digit” is derived from the Latin word for “Finger”.

EE202 DIGITAL ELECTRONICS

Page 9: Ee 202 chapter 1 number and code system

� The decimal system is a positional-value system in which the value of a digit depends on its position.

� For example: consider the decimal number 453. � Digit 4 actually represents 4 hundreds, the 5

represent 5 tens, and the 3 represent 3 units.� In essence, the 4 carries the most weight of the three

digits; it is referred to as the most significant digit (MSD).

� The 3 carries the least weight and is called the least significant digit (LSD).

1.1.1 Decimal Number System

EE202 DIGITAL ELECTRONICS

Page 10: Ee 202 chapter 1 number and code system

� Consider another example, 27. 35

� This number is actually equal to 2 tens plus 7 units plus 3 tenth plus 5 hndredths or 2 x 10 + 7 x 1 + 3 x 0.1 + 5 x 0.01

� The decimal point is used to separate the integer and fractional parts of the number.

1.1.1 Decimal Number System

EE202 DIGITAL ELECTRONICS

Page 11: Ee 202 chapter 1 number and code system

� Moreover, the various positions relative to the decimal point carry weights that can be expressed as powers of 10.

� Example : 2745.214 103

102 101 100 10-1 10-2 10-3

1.1.1 Decimal Number System

2222 7777 4444 5555 .... 2222 1111 4444

MSD LSDDecimal Point

= (2x 103 )+(7x 102 )+(4x 101 )+(5x 100 )+(2x 10-1)+(1x 10-2 )+(4x 10-3 )

Figure 1 : Decimal position values as power of 10

EE202 DIGITAL ELECTRONICS

Page 12: Ee 202 chapter 1 number and code system

� In general any number is simply the sum of products of each digit value and its positional value.

� Unfortunately, Decimal number system does not lend itself to convinient implementation in digital system.

� It is very difficult to design electronics equipment so that it can work with 10 different voltage levels (0-9).

� For this reason, almost every digital system uses the binary number system base-2 as the basic number to design electronics circuits that operate with only two voltage levels.

1.1.1 Decimal Number System

EE202 DIGITAL ELECTRONICS

Page 13: Ee 202 chapter 1 number and code system

� In binary system, there are only two symbols or possible digit values, 0 and 1.

� Even so, this base-2 system can be used to represent any quantity that can be represented in decimal or other number systems.

� All the statements made ealier concering the decimal system are equally applicable to the binary system.

� The binary system is also a positional-value system, where in each binary digit has its own value or weight expressed as a power of 2.

1.1.2 Binary Number System

EE202 DIGITAL ELECTRONICS

Page 14: Ee 202 chapter 1 number and code system

� Example:

• Here,places to the left of the binary point (counterpart of the decimal point) are positive power of 2 and places to the right are negative power of 2.

� Exercise : Find the equivalent in the decimal system for the number 1011.1012

Answer : 11.62510 (How?)

1.1.2 Binary Number System

1111 0000 1111 1111 .... 1111 0000 1111

MSB MSBBinary Point

23 22

21 20

2-1 2-2

2-3

Figure 2 : Binary position values as power of 2

EE202 DIGITAL ELECTRONICS

Page 15: Ee 202 chapter 1 number and code system

� In the binary system, the term binary digit is often abbreviated to the term bit, bit, bit, bit, which we will use henceforth.

1.1.2 Binary Number System

EE202 DIGITAL ELECTRONICS

Page 16: Ee 202 chapter 1 number and code system

1.1.2 Binary Number System

EE202 SEMICONDUCTOR DEVICES

Figure 3 : Binary Counting Sequence

= 8= 8= 8= 8 = 4 = 4 = 4 = 4 = 2 = 2 = 2 = 2 = 1 = 1 = 1 = 1 Decimal Decimal Decimal Decimal equivalentequivalentequivalentequivalent

0000

0000

0011

0101

0123

0000

1111

0011

0101

4567

1111

0000

0011

0101

891011

1111

1111

0011

0101

12131415

23 22

21 20

Weights

LSB

Page 17: Ee 202 chapter 1 number and code system

� Example: What is the largest number that can be represented using

8 bits?

� Solution : 2N

- 1 = 28

= 25510

= 111111112

1.1.2 Binary Number System

EE202 DIGITAL ELECTRONICS

Page 18: Ee 202 chapter 1 number and code system

� Review Questions:

1. What is the decimal equivalent of 11010112?2.What is the next binary number following 101112 in

the counting sequence?3.What is the largest decimal value that can be

represented using 12 bits?

1.1.2 Binary Number System

EE202 DIGITAL ELECTRONICS

Page 19: Ee 202 chapter 1 number and code system

� A Binary number can be converted to decimal by multiplying the weight of each position with the binary digit and adding together.

� Example :Convert the Binary number 101102 to its Decimal equivalent.� Solution:

Binary number 1 0 1 1 02

24 + 23 + 22 + 21 + 20

(24 x 1)+(23 x 0)+(22 x 1)+(21 x 1)+(20 x 0 )= 16 + 0 + 4 + 2 + 0= 2210

1.1.3 Binary to Decimal Conversion

EE202 DIGITAL ELECTRONICS

Page 20: Ee 202 chapter 1 number and code system

� Example :Convert the Fractional Binary Number 101.102 to its Decimal equivalent.� Solution:

Binary Number = 1 0 1 . 1 0Power of 2 position = 22 21 20 . 2-1 2-2

= (22 x 1)+(21 x 0)+(20 x 1) . (2-1 x 1)+(2-2 x 0 )

Decimal Value = 4 + 0 + 1 . 0.5 + 0 = 5.5 10

1.1.3 Binary to Decimal Conversion

EE202 DIGITAL ELECTRONICS

Page 21: Ee 202 chapter 1 number and code system

1.1.3 Binary to Decimal Conversion

EE202 DIGITAL ELECTRONICS

Page 22: Ee 202 chapter 1 number and code system

1.1.3 Decimal To Binary conversion

� The most convenient method is called division by 2 method.

� In which first decimal number will be divided by 2. � The quotient will be dividend for the next step. In each step

the remainder part will be recorded separately. � The 1st reminder of the 1st division will be the LSB in the

Binary Number. � The quotient should repeatedly divide by 2 until the

quotient becomes 0. � The final remainder will be the MSB in Binary number.

EE202 DIGITAL ELECTRONICS

Page 23: Ee 202 chapter 1 number and code system

� Example :

Convert Decimal 2010 to its Binary equivalent.Solution:

2 20 remainder of 0 2 10 remainder of 0 2 5 remainder of 1 2 2 remainder of 0 2 1 remainder 0f 1 0 1 0 1 0 02

1.1.3 Decimal To Binary conversion

EE202 DIGITAL ELECTRONICS

Page 24: Ee 202 chapter 1 number and code system

� When converting a decimal fractional number to its binary, the decimal fractional part will be multiply by 2 till the fractional part gets 0 or till the number of decimal places reached.

1.1.3 Decimal To Binary conversion

EE202 DIGITAL ELECTRONICS

Page 25: Ee 202 chapter 1 number and code system

� Below example show the steps to convert decimal fraction 0.625 to its binary equivalent.

Step 1 : 0.625 will be multiply by 2 ( 0.625 x 2 = 1.25)Step 2 : The integer part will be the MSB in the binary resultStep 3 : The fractional part of the earlier result will be multiply again ( 0.25 x 2 = 0.5 )Step 4 : Each time after the multiplication the integer part of the result will be written as the Binary number.Step 5 : The procedure should continue till the fractional part gets 0.

1.1.3 Decimal To Binary conversion

EE202 DIGITAL ELECTRONICS

Page 26: Ee 202 chapter 1 number and code system

� Example :Convert Decimal 0.62510 to its binary equivalent.Solution:

0.25 x 2 = 0.50 0. 5 x 2 = 1. 00 LSB carried MSB 1 0 1

= 0.62510 = . 1012

1.1.3 Decimal To Binary conversion

EE202 DIGITAL ELECTRONICS

Page 27: Ee 202 chapter 1 number and code system

1.1.4 Binary Addition

� Adding of two binary numbers follows same as addition of two decimal numbers.

� Some times binary addition is very much easier then Decimal or any other number system addition, because in binary you deal with only 2 numbers.

� There are mainly 4 rules should be followed in the process of addition in binary numbers:

sum carryoutRule 1 : 0 + 0 = 0 0Rule 2 : 0 + 1 = 1 1Rule 3 : 1 + 0 = 1 1Rule 4 : 1 + 1 = 0 1

EE202 DIGITAL ELECTRONICS

Page 28: Ee 202 chapter 1 number and code system

Example:Perform Binary Addition for 1012 + 0102

Solution:1 0 12

0 1 02 + 1 1 1Exercise:Perform Binary Addition for 10112 + 01112

Answer: 10 01 02

1.1.4 Binary Addition

EE202 DIGITAL ELECTRONICS

Page 29: Ee 202 chapter 1 number and code system

� When subtracting one binary number A (subtrahend) from another binary number B (Minuend) where B > A, the answer is called the difference.

� There are four basic rules that should be followed in binary subtracting To perform Rule 2 you have to borrow 1 from the next left column.

� The weight of the binary you borrow will be 2.

1.1.5 Binary Subtraction

EE202 DIGITAL ELECTRONICS

Page 30: Ee 202 chapter 1 number and code system

� Minuend (B) Subtrahend (A) Difference Borrow out

� Rule 1 0 - 0 = 0� Rule 2 0 - 1 = 1 with a borrow of 1

� Rule 3 1 - 0 = 1� Rule 4 1 - 1 = 0Example:Subtract binary 1012 from 1102

01 1 01 0 10 0 1 = 0012

1.1.5 Binary Subtraction

EE202 DIGITAL ELECTRONICS

Page 31: Ee 202 chapter 1 number and code system

1.1.8 Signed Binary Numbers

� A signed number consist both positive and negative sign with magnitude.

� The additional bit for representing the sign of the number (+ or -) is known as sign bit.

� in general, 0 in the sign bit represents a positive number and 1 in the sign bit represents a negative number.

� The leftmost bit 0 is the sign bit represent +� The leftmost bit 1 is the sign bit represent -

EE202 DIGITAL ELECTRONICS

Page 32: Ee 202 chapter 1 number and code system

� Therefore the stored number in register A and B is 13 and -13 respectively in Decimal form.

� The signed bit is used to indicate the positive or negative nature of the stored binary numbers.

� Here the magnitude bits are the binary equivalent of the decimal value being represented.

� This is called the sign magnitude system.

1.1.8 Signed Binary Numbers

EE202 DIGITAL ELECTRONICS

Page 33: Ee 202 chapter 1 number and code system

1.1.8 Signed Binary Numbers

� Sign bit (+) A4 A3 A2 A1 A 0

= +13

B4 B3 B2 B1 B0 = - 13

Representing Signed Number

0 0 0 0 1111 1111 0000 1111

1111 1111 1111 0000 1111

EE202 DIGITAL ELECTRONICS

Page 34: Ee 202 chapter 1 number and code system

Example:� Express the Decimal number -46 in 8 bit Signed

magnitude systemSolution:True Binary number for +46 = 00101110Change the sign bit to 1 and remain unchanged magnitude nits = 10101110 = -46

1.1.8 Signed Binary Numbers

EE202 DIGITAL ELECTRONICS

Page 35: Ee 202 chapter 1 number and code system

1.2 Octal Number System

� Octalnumber has eight possible symbols: 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 and used to express binary numbers, which is called as base of 8 number system or Radix of 8.

� Figure: illustrated how it decrease with negative power of 8:

85 84 83 82 81 80 . 8-1 8-2 8-3 8-4 8-5

Decrease with negative power of 8

EE202 DIGITAL ELECTRONICS

Page 36: Ee 202 chapter 1 number and code system

1.2.2 Octal to Binary Conversion

� Any octal number can be represent by 3 bit binary number, such as 0002 to represent 08 and 111 2 to represent 78

Example: Convert 4358 to its Binary equivalent.Solution: 4 3 58

100 011 101 = 1000111012

EE202 DIGITAL ELECTRONICS

Page 37: Ee 202 chapter 1 number and code system

� Exercise:Convert 54.78 to its Binary equivalent.Solution : 5 4 . 78

101 100 . 111 = 101100.1112

1.2.2 Octal to Binary Conversion

EE202 DIGITAL ELECTRONICS

Page 38: Ee 202 chapter 1 number and code system

1.2.1 Binary to Octal Conversion

� This is the reverse form of the octal to binary conversion.� First, the Binary number should be divided into group of

three from LSB.� Then each three-bit binary number is converted to an Octal

form.Example: Convert 1001010112 to its equivalent Octal number.Solution: 100 101 011 4 5 3 = 4 5 38

EE202 DIGITAL ELECTRONICS

Page 39: Ee 202 chapter 1 number and code system

� Sometimes the Binary numberwill not have even groups of 3 bits.

� For those cases, we can add one or two 0s to the left of the MSB of the binary number to fill out the last group.

Example:

Convert 110101102 to its equivalent Octal number. Solution: 011 010 110 3 2 68 =3268 NOTE that a 0 was placed to the left of the MSB to produce even groups of 3 Bits.

1.2.1 Binary to Octal Conversion

EE202 DIGITAL ELECTRONICS

Page 40: Ee 202 chapter 1 number and code system

� Octal number can be converted to decimal by multiplying the weight of each position with the octal number and adding together.

� Example:Convert the Octal number 2578 to its decimal equivalent� Solution: 2578 = (2 x 82 )+ (5 x 81 )+ (7 x 80) = (2 x 64) + (5 x 8) + (7 x 1) = 17510

1.2.2 Octal Number to Decimal Conversion

EE202 DIGITAL ELECTRONICS

Page 41: Ee 202 chapter 1 number and code system

� Exercise :Convert the Octal number 17.78 to its Decimal

equivalentSolution:

17.78 = (1 x 81) + (7 x 80) + (7 x 8-1) = (1 x 8) + (7 x 1) + (7 x .125) = 64.87510

1.2.2 Octal Number to Decimal Conversion

EE202 DIGITAL ELECTRONICS

Page 42: Ee 202 chapter 1 number and code system

� Here we can apply the same method done in decimal to binary conversion. Dividing the decimal number by 8 can do conversion to octal.

Example :Convert 9710 to its Octal equivalent. Solution : 8 97 + remainder of 1 8 12 + remainder of 4 8 1 + remainder of 1 0

1 4 18

1.2.2 Decimal to Octal Conversion

EE202 DIGITAL ELECTRONICS

Page 43: Ee 202 chapter 1 number and code system

Review Question:

1. Convert 6148 to decimal.2. Convert 14610 to Octal, then from Octal to Binary.3. Convert 100111012 to Octal.4. Convert 97510 to Binary by First Coverting to Octal.5. Convert Binary 10101110112 to Decimal by first converting

to Octal.

Answer:1. 396 2. 222, 010010010 3. 2354. 1111001111 5. 699

EE202 DIGITAL ELECTRONICS

Page 44: Ee 202 chapter 1 number and code system

1.3 Hexadecimal Number System

� Hexadecimal number system is called as base 16 number system.

� It uses 10 decimal numbers and 6 alphabetic characters to represent all 16 possible symbols.

� Table below, shows Hexadecimal numbers with its equivalent in decimal and Binary.

EE202 DIGITAL ELECTRONICS

Page 45: Ee 202 chapter 1 number and code system

Hexadecimal Hexadecimal Hexadecimal Hexadecimal NumberNumberNumberNumber

Binary NumberBinary NumberBinary NumberBinary Number Decimal NmberDecimal NmberDecimal NmberDecimal Nmber

0 0000 0

1 0001 1

2 0010 2

3 0011 3

4 0100 4

5 0101 5

6 0110 6

7 0111 7

8 1000 8

9 1001 9

A 1010 10

B 1011 11

C 1100 12

D 1101 13

E 1110 14

F 1111 15

1.3 Hexadecimal Number System

EE202 DIGITAL ELECTRONICS

Page 46: Ee 202 chapter 1 number and code system

1.3.1 Hexadecimal to Binary Conversion

� Hexadecimal number can be represent in Binary form by using 4 bits for each hexadecimal number.

016 can be written in binary = 0000 716 in binary can be written = 0111 A16 in binary can be written = 1010Example:Convert the Hexadecimal A516 to its Binary equivalent.Solution : A 516

1010 01012 = 101001012

EE202 DIGITAL ELECTRONICS

Page 47: Ee 202 chapter 1 number and code system

Exercise:Convert the Hexadecimal 9F216 to its Binary equivalent.Solution: 9 F 2 1011 1111 0010 = 1001111100102

1.3.1 Hexadecimal to Binary Conversion

EE202 DIGITAL ELECTRONICS

Page 48: Ee 202 chapter 1 number and code system

� This is the reverse form of the Hexadecimal to Binary Conversion.

� First the Binary number should be Divided into group of Four bits from LSB.

� Then each four-bit binary number is converted to a Hexadecimal form.

1.3.1 Binary to Hexadecimal Conversion

EE202 DIGITAL ELECTRONICS

Page 49: Ee 202 chapter 1 number and code system

� Example:Convert the Binary 10110110111110102 to its equivalent Hexadecimal number.Solution:

1011 0110 1111 1010

B 6 F A = B6FA16

1.3.1 Binary to Hexadecimal Conversion

EE202 DIGITAL ELECTRONICS

Page 50: Ee 202 chapter 1 number and code system

� Exercise: Convert the Binary 11101001102 to its equivalent Hexadecimal number.

Solution: 0011 1010 01102

3 A 6 = 3A616

1.3.1 Binary to Hexadecimal Conversion

EE202 DIGITAL ELECTRONICS

Page 51: Ee 202 chapter 1 number and code system

1.3.2 Hexadecimal to Decimal Conversion

� Hexadecimal number can be converted to decimal by multiplying the weight of each position of the hexadecimal number (power of 16) and adding togather.

Example: Convert the Hexadecimal number 32716 to its DecimalEquivalent. Solution :

32716 = (3 x 162) + (3 x 161 ) + (7 x 160 ) = ( 3 x 256) + ( 2 x 16 ) + ( 7 x 1 ) = 807 = 807 = 807 = 80710101010

EE202 DIGITAL ELECTRONICS

Page 52: Ee 202 chapter 1 number and code system

Example :

Convert the Hexadecimal number 2AF16 to its Decimal Equivalent.Solution:

2AF16 = (2 x 162)+(10 x 161 )+(15 x 160 ) = (512) + (160) + (15) = 68710

1.3.2 Hexadecimal to Decimal Conversion

EE202 DIGITAL ELECTRONICS

Page 53: Ee 202 chapter 1 number and code system

� Exercise : Convert the Hexadecimal number 1BC216 to its Decimal Equivalent.

Solution: = (1 x 162)+(11 x 162)+(12 x 162 )+(2 x 162) = 710610

1.3.2 Hexadecimal to Decimal Conversion

EE202 DIGITAL ELECTRONICS

Page 54: Ee 202 chapter 1 number and code system

� Here we can apply the same method done in Decimal to Binary conversion.

� Since we need to convert to Hexadecimal, so we have to divide the Decimal number by 16.

� Example :Convert the Decimal 38210 to its Hexadecimal equivalent.Solution: 16 382 + remainder of 14 16 23 + remainder of 7 0 7 E16

1.3.2 Decimal to Hexadecimal Conversion

EE202 DIGITAL ELECTRONICS

Page 55: Ee 202 chapter 1 number and code system

Counting Hexadecimal

� When counting in Hex, each digit position can be incremented (increased by 1) from 0 to F.

� Once a digit position reaches, the value F, it is RESET to 0 and the next digit position is incremented.

� This illustrated in the following Hex counting sequences.

(a). 38, 39, 3A, 3B, 3C, 3D, 3E, 3F, 40, 41, 42(b). 6F8, 6F9, 6FA, 6FB, 6FC, 6FD, 6FE, 6FF, 700

EE202 DIGITAL ELECTRONICS

Page 56: Ee 202 chapter 1 number and code system

Review Question:

1. Convert 24CE16 to Decimal.2. Convert 311710 to Hex, then from Hex to Binary.3. Convert 10010111101101012 to Hex.4. Write the next four numbers in this Hex counting

sequence. E9A, E9B, E9C, E9D, ___,___,___,___5. Convert 35278 to Hex.Answer:1. 9422 2. C2D ; 110000101101 3. 97B5 4. E9E, E9F, EA0, EA1 5. 757

EE202 DIGITAL ELECTRONICS

Page 57: Ee 202 chapter 1 number and code system

1.3.3 1's 1's 1's 1's Complement Form

� The 1's complement form of any binary number is simply obtained by taking the complement form of 0 and 1.

� 1 to 0 and 0 to 1* The range is –(2n-1 – 1) to +(2n-1-1).Example:Find the 1's complement 101001Solution: 1 0 1 0 0 1 Binary Number

0 1 0 1 1 0 1's complement of Binary Number

EE202 DIGITAL ELECTRONICS

Page 58: Ee 202 chapter 1 number and code system

� The 2's complement form of binary number is obtained by taking the complement form of 0, 1 and adding 1 to LSB.

� The range is –(2n-1) to (2n-1-1).Example:Find the 2's complement of 1110010Solution:

1 1 1 0 0 1 0 Binary Number0 0 0 1 1 0 1 1's complement

+ 1 Add 1 0 0 0 1 1 1 0 2's complement

1.3.3 2's 2's 2's 2's Complement Form

EE202 DIGITAL ELECTRONICS

Page 59: Ee 202 chapter 1 number and code system

1.3.3 Signed Number Representing Using 2's Complement

Example:Express the Decimal number -25 in the 2's complement system using 8-bits.Solution:Represent the +25 in Binary for

0 0 0 1 1 0 0 1 1 1 1 0 0 1 1 0 ( 1's complement) +1

1 1 1 0 0 1 1 1 ( 2's complement)

EE202 DIGITAL ELECTRONICS

Page 60: Ee 202 chapter 1 number and code system

1.3.3 2's complement Addition

� The two number in addition are addend and augend which result in the sum.

� The following five cases can be occur when two binary numbers are added;

CASE 1: Both number are positiveStraight Foward addition. Example: +8 and +4 in 5 bits

0 1000 ( + 8, augend) 0 0100 ( + 4, addend) 0 1 1 0 0 ( sum = + 12) signed bit

EE202 DIGITAL ELECTRONICS

Page 61: Ee 202 chapter 1 number and code system

� CASE 2: Positive number larger than negative number

Example: Add two numbers +17 and -6 in six bitsSolution: 0 1 0 0 0 1 (+17) 1 1 1 0 1 0 (-6) 1 0 0 1 0 1 1 (+11)

The Final carry bit is disregarded

1.3.3 2's complement Addition

EE202 DIGITAL ELECTRONICS

Page 62: Ee 202 chapter 1 number and code system

� CASE 3: Positive number smaller than negative number

� Example:� Add two numbers -8 and +4Solution: 1 1 0 0 0 ( -8, augend) 0 0 1 0 0 ( +4, addend) 1 1 1 0 0 ( sum = -4) sign bit

1.3.3 2's complement Addition

Since the SUM is negative, it is in 2's complement form.

EE202 DIGITAL ELECTRONICS

Page 63: Ee 202 chapter 1 number and code system

� Case 4: Both numbers are negative Example: Add two numbers -5 and -9 in 8 bits.Solution: 1 1 1 1 1 0 1 1 (-5)

+ 1 1 1 1 0 1 1 1 (-9) 1 1 1 1 1 0 0 1 0 (-14)

The final carry bit is disregarded

1.3.3 2's complement Addition

Since the SUM is negative, it is in 2's complement form.

EE202 DIGITAL ELECTRONICS

Page 64: Ee 202 chapter 1 number and code system

� when subtracting the binary number ( the subtrahend) from another binary number ( the minuend) then change the sign of the subtrahend and adds it to the minuend.

Case 1: Both numbers are positive : Example:Subtract +41 from +75 in byte.Solution: Minuend ( +75) = 01001011 Subtrahend (+41)=00101001Take the 2's complement form of subtrahend (+41) and add with miuend.

1.3.3 2's complement Subtraction

EE202 DIGITAL ELECTRONICS

Page 65: Ee 202 chapter 1 number and code system

0 1 0 0 1 0 1 1 (+75) 1 1 0 1 0 1 1 1 (-41) 1 0 0 1 0 0 0 1 0 (+34) discard

1.3.3 2's complement Subtraction

EE202 DIGITAL ELECTRONICS

Page 66: Ee 202 chapter 1 number and code system

� CASE 2: Both numbers are negative Example:Subtract -30 from -80 in 8bit.Solution:In this case (-80) - (-30) = ( -80) + (30) 1 0 1 1 0 0 0 0 (-80) - 0 0 0 1 1 1 1 0 (+30) 1 1 0 0 1 1 1 0 (-50)

1.3.3 2's complement Subtraction

EE202 DIGITAL ELECTRONICS

Page 67: Ee 202 chapter 1 number and code system

� CASE 3 :Both numbers are opposite signExample:Subtract -20 from + 24 in byte.Solution:In this case (+24) - (-20) = (+24)+(20)

0 0 0 1 1 0 0 0(+24)0 0 0 1 0 1 0 0 (+20)

0 0 1 0 1 1 0 0 (+44)

1.3.3 2's complement Subtraction

EE202 DIGITAL ELECTRONICS

Page 68: Ee 202 chapter 1 number and code system

1.4 How Binary CODES are Used in Computers

� Binary codes are used in computers representing Decimal digits, alphanumeric characters and symbols.

� When Numbers, letters or words are represented by a speacial group of symbols, we say that they are being encoded, and the group of symbols is called a code.

� When a decimal number is represented by its equivalent binary number, we call it Straight Straight Straight Straight Binary Coding.Binary Coding.Binary Coding.Binary Coding.

EE202 DIGITAL ELECTRONICS

Page 69: Ee 202 chapter 1 number and code system

� BCD- Binary Coded Decimal Code� If each digit of a decimal number is represented by

its binary equivalent, the result is a code called Binary Coded Decimal , BCD.Binary Coded Decimal , BCD.Binary Coded Decimal , BCD.Binary Coded Decimal , BCD.

� To illustrate the BCD code, take a Decimal number such as 874.

� Each digit is changed to its Binary Equivalent as follows :

8 7 4 (Decimal)(Decimal)(Decimal)(Decimal) 1000 0111 0100 (BCD)(BCD)(BCD)(BCD)

1.4.1 BCD 8421 codes

EE202 DIGITAL ELECTRONICS

Page 70: Ee 202 chapter 1 number and code system

� As another example, let us change 943 to its BCD-code representation:

9 4 3 (Decimal) 1001 0100 0011 ( BCD)� Once again, each decimal digit is changed to its straight Binary equivalent.� Note that 4 Bits are always used for each digit.� The BCD code, then represents each digit of the

decimal number by a 4 Bit binary number.

1.4.1 BCD 8421 codes

EE202 DIGITAL ELECTRONICS

Page 71: Ee 202 chapter 1 number and code system

� Clearly only the 4-bit binary numbers from 0000 through 1001 are used.

� The BCD code does not usedoes not usedoes not usedoes not use the numbers 1010, 1011, 1100, 1101, 1110 and 1111.

� In other words, only 10 of the 16 possible 4-bit binary code groups are used.

� If any of the "forbidden" 4-bit numbers ever occurs in a machine using the BCD code, it is usually an indication that an error has occurred.

1.4.1 BCD 8421 codes

EE202 DIGITAL ELECTRONICS

Page 72: Ee 202 chapter 1 number and code system

Example:Convert 0110100000111001 (BCD) to its decimal equivalent.Solution:Divide the BCD number into 4-bit groups and convert each to decimal. 0110 1000 0011 1001 6 8 3 9

1.4.1 BCD 8421 codes

EE202 DIGITAL ELECTRONICS

Page 73: Ee 202 chapter 1 number and code system

Exercise:Convert the BCD number 011111000001 to its Decimal equivalent.Solution: 0111 1100 0001 7 1 Forbidden code group indicates error in BCD number

1.4.1 BCD 8421 codes

EE202 DIGITAL ELECTRONICS

Page 74: Ee 202 chapter 1 number and code system

1.4.1 Comparison of BCD and Binary

� It is important to realize that BCD is not another number system like binary, octal, decimal and Hexadecimal.

� It is also important to understand that a BCD number is not the same as a straight binary number.

� A straight binary code takes the complete decimal number and represents it in binary.

� BCD code converts each decimal digit to binary individually.

� Example:13710 = 100010012 (binary)

13710 = 0001 0011 0111 (BCD)

EE202 DIGITAL ELECTRONICS

Page 75: Ee 202 chapter 1 number and code system

1.4.2 Alphanumeric Codes

� A computer should recognize codes that represent letters of the alphabet, puntuation marks, and other special characters as well as numbers.

� A complete alphanumeric code would include the 26 lowercase latters, 26 uppercase latter, 10 numeric digits, 7 punctuation marks, and anywhere from 20 to 40 other characters such as + / * # and so on.

� we can say that an alphanumeric code represents all of the various characters and functions that are found on a standard typewriter or computer keyboard.

EE202 DIGITAL ELECTRONICS

Page 76: Ee 202 chapter 1 number and code system

� The most widely used alphanumeric code.� American Standard Code for Information

interchange (ASCII).� Pronounced "askee"Refer table next slide to see : Partial Listing of ASCII code.

1.4.2 Alphanumeric Codes - ASCII Code

EE202 DIGITAL ELECTRONICS

Page 77: Ee 202 chapter 1 number and code system

ASCII Reference TableASCII Reference TableASCII Reference TableASCII Reference TableASCII Reference TableASCII Reference TableASCII Reference TableASCII Reference Table

EE202 DIGITAL ELECTRONICS

Page 78: Ee 202 chapter 1 number and code system

Extended ASCII Codes

EE202 DIGITAL ELECTRONICS

Page 79: Ee 202 chapter 1 number and code system

Example:The following is a message encoded in ASCII code. What is the message?

1001000 1000101 1001100 1010000Solution:Convert each 7-bit code to its Hexadecimal equivalent. The results are : 48 45 4C 50Now, locate these Hexadecimal values in table ASCII and determine the character represented by each. The results are: H E L P

1.4.2 Alphanumeric Codes - ASCII Code

EE202 DIGITAL ELECTRONICS

Page 80: Ee 202 chapter 1 number and code system

ReferencesReferencesReferencesReferences

� "Digital Systems Principles And Application" Sixth Editon, Ronald J. Tocci.

� "Digital Systems Fundamentals" P.W Chandana Prasad, Lau Siong Hoe, Dr. Ashutosh Kumar Singh, Muhammad Suryanata.

Page 81: Ee 202 chapter 1 number and code system

The End Of Chapter 1...

� Do Review Questions� Quiz 1 for Chapter 1- be prepared!!

EE201 DIGITAL ELECTRONICS