Download as pdf or txt
Download as pdf or txt
You are on page 1of 81

CHAPTER 1:

NUMBER AND
CODE SYSTEMS

EE202
DIGITAL ELECTRONICS

BY: SITI SABARIAH SALIHIN

sabariah@psa.edu.my www.sabariahsalihin.com
CHAPTER 1:
NUMBER AND
CODE SYSTEMS
Programme Learning Outcomes, PLO
Upon 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, CLO


� CLO 1 : Illustrate the knowledge of Digital Number Systems, codes and
logic operations correctly.

EE202 DIGITAL ELECTRONICS


CHAPTER 1:
NUMBER AND
CODE SYSTEMS
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.

EE202 DIGITAL ELECTRONICS


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


1.1 INTRODUCTION

� 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.

EE202 DIGITAL ELECTRONICS


1.1 INTRODUCTION

� 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.

EE202 DIGITAL ELECTRONICS


1.1 INTRODUCTION

� 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 .

EE202 DIGITAL ELECTRONICS


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


1.1.1 Decimal Number 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).
EE202 DIGITAL ELECTRONICS
1.1.1 Decimal Number 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.

EE202 DIGITAL ELECTRONICS


1.1.1 Decimal Number System

� Moreover, the various positions relative to the


decimal point carry weights that can be expressed as
powers of 10.
� Example : 2745.214 Figure 1 : Decimal position values as power of 10
3 2 1 0 -1 -2 -3
10 10 10 10 10 10 10

2 7 4 5 . 2 1 4

MSD Decimal Point LSD

3 2 1 0 -1 -2 -3
= (2x 10 )+(7x 10 )+(4x 10 )+(5x 10 )+(2x 10 )+(1x 10 )+(4x 10 )

EE202 DIGITAL ELECTRONICS


1.1.1 Decimal Number 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.

EE202 DIGITAL ELECTRONICS


1.1.2 Binary Number 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.

EE202 DIGITAL ELECTRONICS


1.1.2 Binary Number System

� Example: Figure 2 : Binary position values as power of 2


1 -1 -2 -3
3
2
2
2 2
0
2 2 2
2

1 0 1 1 . 1 0 1

MSB MSB
Binary Point

• 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?)

EE202 DIGITAL ELECTRONICS


1.1.2 Binary Number System

� In the binary system, the term binary digit is often


abbreviated to the term bit, which we will use
henceforth.

EE202 DIGITAL ELECTRONICS


1.1.2 Binary Number System
Figure 3 : Binary Counting Sequence
3
Weights 2 =8 2 =4
2
2 =2
1
2 =1
0
Decimal
LSB equivalent
0 0 0 0 0
0 0 0 1 1
0 0 1 0 2
0 0 1 1 3
0 1 0 0 4
0 1 0 1 5
0 1 1 0 6
0 1 1 1 7
1 0 0 0 8
1 0 0 1 9
1 0 1 0 10
1 0 1 1 11
1 1 0 0 12
1 1 0 1 13
1 1 1 0 14
1 1
EE202 1 DEVICES
SEMICONDUCTOR 1 15
1.1.2 Binary Number System

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

� Solution :
N 8
2 - 1 =2
= 255 10

= 111111112

EE202 DIGITAL ELECTRONICS


1.1.2 Binary Number 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?

EE202 DIGITAL ELECTRONICS


1.1.3 Binary to Decimal Conversion

� 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
4 3 2 1 0
2 +2 +2 +2 +2
4 3 2 1 0
(2 x 1)+(2 x 0)+(2 x 1)+(2 x 1)+(2 x 0 )
= 16 + 0 + 4 + 2 + 0
= 2210
EE202 DIGITAL ELECTRONICS
1.1.3 Binary to Decimal Conversion

� Example :
Convert the Fractional Binary Number 101.102 to its
Decimal equivalent.
� Solution:
Binary Number = 1 0 1 . 1 0
2 1 0 -1 -2
Power of 2 position = 2 2 2 . 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

EE202 DIGITAL ELECTRONICS


1.1.3 Binary to Decimal Conversion

EE202 DIGITAL ELECTRONICS


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


1.1.3 Decimal To Binary conversion

� 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

EE202 DIGITAL ELECTRONICS


1.1.3 Decimal To Binary conversion

� 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.

EE202 DIGITAL ELECTRONICS


1.1.3 Decimal To Binary conversion

� 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
result
Step 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.
EE202 DIGITAL ELECTRONICS
1.1.3 Decimal To Binary conversion

� 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

EE202 DIGITAL ELECTRONICS


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 carryout
Rule 1 : 0 + 0 = 0 0
Rule 2 : 0 + 1 = 1 1
Rule 3 : 1 + 0 = 1 1
Rule 4 : 1 + 1 = 0 1
EE202 DIGITAL ELECTRONICS
1.1.4 Binary Addition

Example:
Perform Binary Addition for 1012 + 0102
Solution:
1 0 12
0 1 02 +
1 1 1
Exercise:
Perform Binary Addition for 10112 + 01112

Answer: 10 01 02

EE202 DIGITAL ELECTRONICS


1.1.5 Binary Subtraction

� 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.

EE202 DIGITAL ELECTRONICS


1.1.5 Binary Subtraction

� 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 = 0
Example:
Subtract binary 1012 from 1102
0
1 1 0
1 0 1
0 0 1 = 0012
EE202 DIGITAL ELECTRONICS
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


1.1.8 Signed Binary Numbers

� 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.

EE202 DIGITAL ELECTRONICS


1.1.8 Signed Binary Numbers

� Sign bit (+) A4 A3 A2 A1 A0


0 1 1 0 1
= +13

B4 B3 B2 B1 B0
1 1 1 0 1
= - 13

Representing Signed Number

EE202 DIGITAL ELECTRONICS


1.1.8 Signed Binary Numbers

Example:
� Express the Decimal number -46 in 8 bit Signed
magnitude system
Solution:
True Binary number for +46
= 00101110
Change the sign bit to 1 and remain unchanged
magnitude nits
= 10101110 = -46

EE202 DIGITAL ELECTRONICS


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:

5 4 3 2 1 0 -1 -2 -3 -4 -5
8 8 8 8 8 8 . 8 8 8 8 8
Decrease with negative power of 8

EE202 DIGITAL ELECTRONICS


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


1.2.2 Octal to Binary Conversion

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

101 100 . 111 = 101100.1112

EE202 DIGITAL ELECTRONICS


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
1.2.1 Binary to Octal Conversion

� 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.

EE202 DIGITAL ELECTRONICS


1.2.2 Octal Number to Decimal Conversion

� 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:
2 1 0
2578 = (2 x 8 )+ (5 x 8 )+ (7 x 8 )
= (2 x 64) + (5 x 8) + (7 x 1)
= 17510

EE202 DIGITAL ELECTRONICS


1.2.2 Octal Number to Decimal Conversion

� Exercise :
Convert the Octal number 17.78 to its Decimal
equivalent
Solution:
1 -1
17.78 = (1 x 8 ) + (7 x 8 ) + (7 x 8 )
0

= (1 x 8) + (7 x 1) + (7 x .125)
= 64.87510

EE202 DIGITAL ELECTRONICS


1.2.2 Decimal to Octal Conversion

� 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
EE202 DIGITAL ELECTRONICS
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 1010111011 2 to Decimal by first converting
to Octal.
Answer:
1. 396 2. 222, 010010010 3. 235
4. 1111001111 5. 699

EE202 DIGITAL ELECTRONICS


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


1.3 Hexadecimal Number System
Hexadecimal Binary Number Decimal Nmber
Number
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
EE202 DIGITAL ELECTRONICS
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 = 1010
Example:
Convert the Hexadecimal A516 to its Binary equivalent.
Solution : A 516

1010 01012 = 101001012

EE202 DIGITAL ELECTRONICS


1.3.1 Hexadecimal to Binary Conversion

Exercise:
Convert the Hexadecimal 9F216 to its Binary
equivalent.
Solution:
9 F 2

1011 1111 0010 = 100111110010 2

EE202 DIGITAL ELECTRONICS


1.3.1 Binary to Hexadecimal Conversion

� 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.

EE202 DIGITAL ELECTRONICS


1.3.1 Binary to Hexadecimal Conversion

� Example:
Convert the Binary 1011011011111010 2 to its equivalent
Hexadecimal number.
Solution:
1011 0110 1111 1010

B 6 F A = B6FA16

EE202 DIGITAL ELECTRONICS


1.3.1 Binary to Hexadecimal Conversion

� Exercise:
Convert the Binary 1110100110 2 to its
equivalent Hexadecimal number.
Solution:
0011 1010 01102

3 A 6 = 3A616

EE202 DIGITAL ELECTRONICS


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 Decimal
Equivalent.
Solution :
2 1 0
32716 = (3 x 16 ) + (3 x 16 ) + (7 x 16 )
= ( 3 x 256) + ( 2 x 16 ) + ( 7 x 1 )
= 807 10

EE202 DIGITAL ELECTRONICS


1.3.2 Hexadecimal to Decimal Conversion

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

EE202 DIGITAL ELECTRONICS


1.3.2 Hexadecimal to Decimal Conversion

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

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

EE202 DIGITAL ELECTRONICS


1.3.2 Decimal to Hexadecimal Conversion

� 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
EE202 DIGITAL ELECTRONICS
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


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


1.3.3 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 101001
Solution: 1 0 1 0 0 1 Binary Number

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

EE202 DIGITAL ELECTRONICS


1.3.3 2's Complement Form
� 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 1110010
Solution:
1 1 1 0 0 1 0 Binary Number
0 0 0 1 1 0 1 1's complement
+ 1 Add 1
0 0 0 1 1 1 0 2's complement

EE202 DIGITAL ELECTRONICS


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


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 positive
Straight 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


1.3.3 2's complement Addition

� CASE 2: Positive number larger than negative


number
Example:
Add two numbers +17 and -6 in six bits
Solution:
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

EE202 DIGITAL ELECTRONICS


1.3.3 2's complement Addition

� CASE 3: Positive number smaller than negative


number
� Example:
� Add two numbers -8 and +4
Solution:
1 1 0 0 0 ( -8, augend)
0 0 1 0 0 ( +4, addend)
1 1 1 0 0 ( sum = -4)
Since the SUM is negative,
sign bit it is in 2's complement form.

EE202 DIGITAL ELECTRONICS


1.3.3 2's complement Addition

� 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)
Since the SUM is negative,
it is in 2's complement form.
The final carry bit is disregarded

EE202 DIGITAL ELECTRONICS


1.3.3 2's complement Subtraction

� 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)=00101001
Take the 2's complement form of subtrahend (+41) and add
with miuend.

EE202 DIGITAL ELECTRONICS


1.3.3 2's complement Subtraction

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

discard

EE202 DIGITAL ELECTRONICS


1.3.3 2's complement Subtraction

� 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)

EE202 DIGITAL ELECTRONICS


1.3.3 2's complement Subtraction

� CASE 3 :
Both numbers are opposite sign
Example:
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)

EE202 DIGITAL ELECTRONICS


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
Binary Coding.

EE202 DIGITAL ELECTRONICS


1.4.1 BCD 8421 codes

� 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.
� 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)
1000 0111 0100 (BCD)
EE202 DIGITAL ELECTRONICS
1.4.1 BCD 8421 codes

� 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.

EE202 DIGITAL ELECTRONICS


1.4.1 BCD 8421 codes

� Clearly only the 4-bit binary numbers from 0000


through 1001 are used.
� The BCD code does 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.

EE202 DIGITAL ELECTRONICS


1.4.1 BCD 8421 codes

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

EE202 DIGITAL ELECTRONICS


1.4.1 BCD 8421 codes

Exercise:
Convert the BCD number 011111000001 to its Decimal
equivalent.
Solution:
0111 1100 0001
7 1

Forbidden code group indicates error in


BCD number

EE202 DIGITAL ELECTRONICS


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


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


1.4.2 Alphanumeric Codes - ASCII Code

� 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.

EE202 DIGITAL ELECTRONICS


ASCII Reference Table

EE202 DIGITAL ELECTRONICS


Extended ASCII Codes

EE202 DIGITAL ELECTRONICS


1.4.2 Alphanumeric Codes - ASCII Code

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

EE202 DIGITAL ELECTRONICS


References

� "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.
The End Of Chapter 1...

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

EE201 DIGITAL ELECTRONICS

You might also like