You are on page 1of 62

Microprocessor and Digital

Logic

Chapter

Chapt. 1
ECEG122 Microprocessor and Digital Logic
Chapter 1

Number System and Codes

ECEG122 Microprocessor and Digital Logic


• Chapter 1: Number System and Codes
1.1 Efficiency of a number system
1.2 Radix(base ) conversion
1.3 Arithmetic with base other than ten
1.4 Alphanumeric codes, various codes, error
detection and correction

ECEG122 Microprocessor and Digital Logic


1.1 Efficiency of a number system
 A bit is the most basic unit of information in a
computer.
• It is a state of “on” or “off” in a digital circuit.
• Sometimes they represent high or low voltage
 A Nibble is a group of four bits
 A byte is a group of eight bits.. It is the smallest
possible addressable unit of computer storage.

ECEG122 Microprocessor and Digital Logic


1.1 Efficiency of a number system
 A word is a contiguous group of bytes.
• Words can be any number of bits or bytes.
• Word sizes of 16, 32, or 64 bits are most common.
 A word is a fixed-sized group of bits that are handled together by the machine.
• The number of bits in a word (the word size or word length) is an important
characteristic of computer architecture.
• Word sizes of 16, 32, or 64 bits are most common.
 Word size /8 bits=block or bytes
Example: A Word consists of 32 bits, which is equal to 4 bytes
1 KILO = 1024 bytes ,
1 MEGA = 103 K B,
1 GIGA = 103 M B,1 TERA = 103 G B

ECEG122 Microprocessor and Digital Logic


The following are some of the technical terms used in binary system:

• Bit: It is the smallest unit of information used in a computer system. It


can either have the value 0 or 1. Derived from the words Binary ditIT.
• Nibble: It is a combination of 4 bits.
• Byte: It is a combination of 8 bits.
• Word: It is a combination of 16 bits.
• Double word: It is a combination of 32 bits.
• Kilobyte (KB): It is used to represent the 1024 bytes of information.
• Megabyte (MB): It is used to represent the 1024 KBs of information.
• Gigabyte (GB): It is used to represent the 1024 MBs of information

ECEG122 Microprocessor and Digital Logic


Powers of Two

 The first 24 numbers obtained from 2 to the power of n are listed. In


digital systems, we refer to 210 as K (kilo), 220 as M (mega), 230 as G
(giga), and 2140 as T (tera). Thus,
4K 22 × 210 = 212 = 4096 and 16M 24 × 220 = 224 = 16,777,216

ECEG122 Microprocessor and Digital Logic


Number Systems
 A number system defines a set of values used to represent quantity.
 Today the most common number system in use is Arabic system.
 But, the number systems can be categorized in to two broad
categories:

1. Positional number systems and


2. Non-positional number systems.

 Non-Positional number systems: - is a method of counting on fingers


such as I for 1, II for 2, III for 3, IIII for 4 etc. It was very difficult to
perform arithmetic with such a number system, as it had no symbol
for zero

ECEG122 Microprocessor and Digital Logic


 Positional number systems: - the value of each digit in a number is defined not
only by the symbol but also by the symbol’s position. They have a base or radix.
 In positional number system there are only a few symbols called digits, and these
symbols represent different values depending on the position they occupy in the
number.
 The value of each digit in such a number is determined by three considerations.

 The digit itself.

 The position of the digit in the number, and

 The base or radix of the number system(where base is determined as the total
number of digits available in the number system)

ECEG122 Microprocessor and Digital Logic


• In a computer, everything is a number whether it may be
numbers, alphabets, punctuation marks etc. Eventually,
the number systems that can are generally used by the
computers are:

ECEG122 Microprocessor and Digital Logic


Radix( Base ) Conversion

ECEG122 Microprocessor and Digital Logic


Decimal to Binary
• Technique
– Divide by two, keep track of the remainder
– First remainder is bit 0 (LSB, least-significant bit)
– Second remainder is bit 1
– Etc.

ECEG122 Microprocessor and Digital Logic


Decimal to Binary
• Conversion of Decimal to Binary
– Example-1: Determine the binary equivalent of (36) 10

2 36 Remainder
Least Significant Bit (LSB)
2 18 0
2 9 0
2 4 1
2 2 0
2 1 0
0 1 Most Significant Bit (MSB)

 Taking the reminder in Reverse order we have 100100. thus (36) 10 = (100100) 2.

.
ECEG122 Microprocessor and Digital Logic 13
Example
12510 = ?2 2 125
2 62 1
2 31 0
2 15 1
2 7 1
2 3 1
2 1 1
0 1

12510 = 11111012

ECEG122 Microprocessor and Digital Logic


37 / 2 = 18 remainder 1 (binary number will end with 1) : LSB
18 / 2 = 9 remainder 0
9 / 2 = 4 remainder 1
4 / 2 = 2 remainder 0
2/2= 1 remainder 0
1/2= 0 remainder 1 (binary number will start with 1) : MSB
Read the result upward to give an answer of 3710 = 1001012

ECEG122 Microprocessor and Digital Logic


Binary to Decimal
 Technique
Multiply each bit by 2n, where n is the “weight” of the
bit
The weight is the position of the bit, starting from 0 on
the right
Add the results

ECEG122 Microprocessor and Digital Logic


Example
Bit “0”

1010112 => 1 x 20 = 1
1 x 21 = 2
0 x 22 = 0
1 x 23 = 8
0 x 24 = 0
1 x 25 = 32
4310

ECEG122 Microprocessor and Digital Logic


– Binary-to-Decimal Conversions
1011.1012 = (1 x 23) + (0 x 22)+ (1 x 21) + (1 x 2o) + (1 x 2-1) + (0 x 2-2) + (1 x 2-3)
= 810+ 0 + 210 + 110 + 0.510 + 0 + 0.12510
= 11.62510

ECEG122 Microprocessor and Digital Logic


Octal to Decimal
• Technique
– Multiply each bit by 8n, where n is the “weight”
of the bit
– The weight is the position of the bit, starting
from 0 on the right
– Add the results

ECEG122 Microprocessor and Digital Logic


Example

7248 => 4 x 80 = 4
2 x 81 = 16
7 x 82 = 448
46810

ECEG122 Microprocessor and Digital Logic


Octal to Binary
• Technique
– Convert each octal digit to a 3-bit equivalent
binary representation

ECEG122 Microprocessor and Digital Logic


Example
7058 = ?2

7 0 5

111 000 101

7058 = 1110001012

ECEG122 Microprocessor and Digital Logic


Decimal to Octal
• Technique
– Divide by 8
– Keep track of the remainder

ECEG122 Microprocessor and Digital Logic


Example
123410 = ?8

8 1234
8 154 2
8 19 2
8 2 3
0 2

123410 = 23228

ECEG122 Microprocessor and Digital Logic


Decimal to Hexadecimal
• Technique
– Divide by 16
– Keep track of the remainder

ECEG122 Microprocessor and Digital Logic


Example
123410 = ?16

16 1234
16 77 2
16 4 13 = D
0 4

123410 = 4D216

ECEG122 Microprocessor and Digital Logic


Hexadecimal to Decimal
• Technique
– Multiply each bit by 16n, where n is the
“weight” of the bit
– The weight is the position of the bit, starting
from 0 on the right
– Add the results

ECEG122 Microprocessor and Digital Logic


Example

ECEG122 Microprocessor and Digital Logic


ECEG122 Microprocessor and Digital Logic
Hexadecimal to Binary
• Technique
– Convert each hexadecimal digit to a 4-bit
equivalent binary representation

ECEG122 Microprocessor and Digital Logic


Example
10AF16 = ?2

1 0 A F

0001 0000 1010 1111

10AF16 = 00010000101011112

ECEG122 Microprocessor and Digital Logic


Arithmetic System

ECEG122 Microprocessor and Digital Logic


Arithmetic System

Binary Addition Binary Subtraction


Input Output
X Y Sum (S) Carry (R) Input Output
0 0 0 0 X Y Difference (D) Borrow (B)
0 1 1 0 0 0 0 0
1 0 1 0 0 1 1 1
1 1 0 1 1 0 1 0
1 1 0 0

Example: Add the binary numbers 1111 and 1010.


1 1 1 1
+ 1 0 1 0

1 1 0 0 1 => sum is (11001) 2 .

ECEG122 Microprocessor and Digital Logic 33


Octal Arithmetic

Octal Addition Octal Subtraction


– First, add the two digits of the • In the octal subtraction, the
unit column of the octal number
in decimal. method, which we have adopted,
– This process is repeated for is similar to that of binary
each larger significant digit of subtraction method. The only
the octal number.
difference lies in the carry part.
– During the process of addition,
if the sum is less than or equal During octal subtraction instead
to 7, then it can be directly of 1, we will borrow 8 and the
written as octal digit.
rest of steps are similar to that of
– If the sum is greater than 7,
then subtract 8 from that binary subtraction.
particular digit and carry 1 to
the next digit position.

ECEG122 Microprocessor and Digital Logic 34


ECEG122 Microprocessor and Digital Logic 35
Hexadecimal Arithmetic:
• Hexadecimal Addition
 First add the unit column of • Hexadecimal Subtraction
the hexadecimal digits in
decimal.  The hexadecimal subtraction
 This process is repeated for is based on the same
each larger significant digit of principles as of binary
the hexadecimal number. subtraction. In this
 During the process of addition, subtraction, 16 will be used as
observe if the sum is 15 or
less, then it can be directly borrow instead of 1. The rest
expressed as hexadecimal of steps are similar to the
digit. binary subtraction.
 If the sum is greater than 15,
then subtract 16 from that
particular digit and carry 1 to
the next digit position.

ECEG122 Microprocessor and Digital Logic 36


ECEG122 Microprocessor and Digital Logic 37
Digital Codes
&
Error Detection and Correction

ECEG122 Microprocessor and Digital Logic


Alphanumeric codes, various codes, error detection and correction

• Code is a group of symbols


• Code is a systematic use of a given set of symbols for representing
information
• Code: A set of n-bit strings in which different bit strings
represent different numbers or other things.
• Weighted code :- Each positions are represent specific weight
 Eg. 8 4 2 1 ,2 4 2 1
• Non-weighted code:- non positional codes
 Eg ex-3,GrayCode

ECEG122 Microprocessor and Digital Logic


Alphanumeric codes, various codes, error detection and correction

• Sequential codes:- Each succeeding code is one binary numbers


greater than the preceding code. Ex 8 4 2 1 , ex-3
• Alphanumerical codes:-we can represent number, characters,
symbol and small Instruction Ex. ASCII

ECEG122 Microprocessor and Digital Logic


Reflection codes(Self complements code )
• Reflection codes(Self complements code ) :-9 is complement of 1
8 complement 1 , 7 complement 2……..
• 2421 (self-complementing code) word for the 9’s complement of
any digit may be obtained by complementing the individual bits of
the digit’s code word)
• The codes that represent the pair of complementary digits are complementary of
each other

ECEG122 Microprocessor and Digital Logic


4-Bit Binary Coded Decimal
(BCD) Systems
• The 4-bit BCD system is usually employed by the computer
systems to represent and process numerical data only.
To represent 10 decimal digits(0000:0 ….1001: 9), at
least need 4 bits.
• (Each decimal number ((base 10 i.e 0,1,2…9)) Represent by a 4 bit
Binary binary (0,1) number )
• In the 4-bit BCD system, each digit of the decimal number is
Represented to its corresponding 4-bit binary sequence.
• The two most popular 4-bit BCD systems are:
 Weighted 4-bit BCD code
 Excess-3 (XS-3) BCD code
ECEG122 Microprocessor and Digital Logic
Weighted 4-Bit BCD Code
• The weighted 4-bit BCD code is more commonly known as 8421
weighted code (pronounce eight , four , two, one ).
8421 and BCD codes are the same
• It is called weighted code because it encodes the decimal system
into binary system by using the concept of positional weighting
into consideration.
• In this code, each decimal digit is encoded into its 4-bit binary
number in which the bits from left to right have the weights 8, 4, 2,
and 1, respectively.

ECEG122 Microprocessor and Digital Logic


Weighted 4-Bit BCD Code

 Apart from 8421, some other weighted BCD codes are 4221, 2421
and 5211

ECEG122 Microprocessor and Digital Logic


Weighted 4-Bit BCD Code
• Example :- Represent the decimal number 5327 in 8421 BCD
code.
 The corresponding 4-bit 8421 BCD representation of decimal digit 5 is 0101
 The corresponding 4-bit 8421 BCD representation of decimal digit 3 is 0011
 The corresponding 4-bit 8421 BCD representation of decimal digit 2 is 0010
 The corresponding 4-bit 8421 BCD representation of decimal digit 7 is 0111
 Therefore, the 8421 BCD representation of decimal number 5327 is
0101001100100111.

ECEG122 Microprocessor and Digital Logic


Binary Coded Decimal (BCD)
Example Represent the decimal number 938 in 8421 BCD code.

8 4 2 1 8 4 2 1 8 4 2 1
1 0 0 1 0 0 1 1 1 0 0 0
8+0+0+1 0+0+2+1 8+0+0+0
9 3 8

• Therefore 1001 0011 1000 in BCD = 938 in denary.

ECEG122 Microprocessor and Digital Logic


Invalid BCD Code
• In BCD Decimal number Represent by 4 Bit binary number
• 24 = 16 out of 16 possibility we represent only 10. because we have
only 10 decimal number from 0 to 9
• But we can’t represent the rest possibility (10,11,12,13,14,15) are
decimal number not decimal digit.
• Example 10 has two decimal digital 0 and 1 by combining both 1
and 0 we get Decimal number
10 xxxx
11 xxxx
12 xxxx Invalid /Don’t care
13 xxxx
14 xxxx
15 xxxx

ECEG122 Microprocessor and Digital Logic


BCD to Decimal Covert
• (17)10 It is not decimal digit but decimal number. It consists of
two decimal digit the first one is 1 and the second one is 7
• To convert BCD to Decimal start from the right make a group of 4
bit
• Example. Find the decimal number of the following BCD number
1001001
• Solution:- make a group of four bit start from the right
100 1001
4 9
• BCD represent behind nine called as packed BCD number
Example 10,20,134, 157…….

ECEG122 Microprocessor and Digital Logic


Excess-3 Code
• The Excess-3 (XS-3) BCD code does not use the principle of
positional weights into consideration while converting the decimal
numbers to 4-bit BCD system. Therefore, we can say that this code is
a non-weighted BCD code.
• The function of XS-3 code is to transform the decimal numbers into
their corresponding 4-bit BCD code.
• In this code, the decimal number is transformed to the 4-bit BCD
code by first and adding 3(0011) to all the digits of the number and
then converting the excess digits, so obtained, into their
corresponding 8421 BCD code.
• Therefore, we can say that the XS-3 code is strongly related with 8421
BCD code in its functioning.

ECEG122 Microprocessor and Digital Logic


Excess-3 Code
• To Convert Decimal to Ex-3
• Decimal BCD Code(8-4-2-1) Add 3 Excess-3
Eg 5 0 1 01 + 0011 1000
• 1000 is the excess-3 code of 5
• Ex-3 code is 4 bit code 0 to 9

ECEG122 Microprocessor and Digital Logic


Example
• Example :- find the xe-3 code for decimal number 24
• Solution:-
 Step 1. first find the BCD form of 24 = 0010 0100
 Step 2 Add 3 in both 2 and 4 form of BCD 0010 0100
+ 0011 + 0011
0101 0111
 0101 0111 57 is X3 form of 24
• Example :- find the decimal number 85 to Xe-3
Solution:- Add 3 to each digit of the given decimal number as: 8+3=11 and 5+3=8
The corresponding 4-bit 8421 BCD representation of the decimal digit 11 is 1011.
The corresponding 4-bit 8421 BCD representation of the decimal digit 8 is 1000.
Therefore, the XS-3 BCD representation of the decimal number 85 is 1011 1000.

ECEG122 Microprocessor and Digital Logic


Introduction to Gray Code
• It also known as Reflected Binary Code( RBC )
• It call it Gray code after Frank Gray
• It is un weighted code
• It is binary numerical system two successive value differentiate
by only one bit
• Gray code is another important code that is also used to convert the
decimal number into 8-bit binary sequence. However, this
conversion is carried in a manner that the contiguous digits of the
decimal number differ from each other by one bit only.
• Gary Code widely used in error correction and detection in digital
communication

ECEG122 Microprocessor and Digital Logic


Binary to Gray Code
• Step1:- Record MSB as it is
• Step2:- Add the MSB to the next bit, record the sum and neglect the carry
• Step3:- Repeat the process
• Example find the Gray code of 10110 binary number

• Answer 11101

ECEG122 Microprocessor and Digital Logic


Gray to Binary Code
• Step1:- Record MSB as it is( from the given Gray code)
• Step2:- Add the MSB of binary number to the next most significant bit of gray code
number , record the sum and neglect the carry
• Step3:- Repeat the process
Example convert Gray code
1101111 to Binary

• Ans 1001010

ECEG122 Microprocessor and Digital Logic


What is Parity
• Parity :- it is the Concept detect errors
• A single bit error is detected by it
• The method of parity is widely used as a method of error detection.
 Extra bit known as parity is added to data word
 The new data word is then transmitted.
• There are Two type of parity systems ( Add a Parity Bit to the word )
 Even Parity: Make the parity bit 1 bit if needed to make number 1 of bits
even, else make it 0.
 Odd Parity : Make the parity bit a 1 bit if needed to make number of 1 bits
odd, else make it 0.

ECEG122 Microprocessor and Digital Logic


Parity
• Example
Even Parity Odd parity
11001 110011 110010
11110 111100 111101
11000 110000 110001

• Parity bit can detect odd number of errors but not even number of errors.
Example: For odd parity numbers,
10011  10001 (detected)
10011  10101 (non detected)

ECEG122 Microprocessor and Digital Logic


Hamming Code –Error Detection
• Given by R.W hamming
• Easy to implementation
• Common used 7 bit hamming commonly
• Rule :- data we want transmit
• Parity bit:- the extra bit stream to send along with data bit to detect
the error
• In 7 bit hamming code we have 4 bits data and 3bit parity
• Hamming code has tow part the parity and data bit
• Parity bit(3) the position of parity bit is 2n (where n=0,1,2,4…….n)
so 20=1 ,21 =2 , 22 = 4……….. the position of parity bit
• Databit (4) rest of bit is data bit (Among 7 bit hamming )

ECEG122 Microprocessor and Digital Logic


Hamming Code –Error Detection
• Hamming codes are a class of codes that use combinations of parity
checks to both detect and correct errors.
• They add a group of parity check bits to the data bits.
• For ease of visualization, intersperse the parity bits within the data
bits;
• A given parity bit is computed from data bits whose bit numbers
contain a 1 at the parity bit number.

ECEG122 Microprocessor and Digital Logic


Hamming Code

• P= parity and D= Data


• Thus each bit takes part in a different combination of parity checks.
• When the word is checked, if only one bit is in error, all the parity bits that use it in
their computation will be incorrect.

ECEG122 Microprocessor and Digital Logic


Example
• Example :- lets us suppose we want transfer a 4 bit data
having the value 1011in even parity. Depending upon the
data find the value of P1,P2 & P4
• Soln :- lets first make 7 bit hamming code
D7 D6 D5 D3
1 0 1 P4 1 P2 P1

• P1= D3D5D7 p1= 111 it is even parity so the value of P1=1


• P2=D3D6D7 p2=101 it is even parity so the value of P2=0
• P4=D5D6D7 P4=101 it is even parity so the value of p4=0
• So the data is transfer in the Form of 1010101
D7 D6 D5 P4 D3 P2 P1
1 0 1 0 1 0 1

ECEG122 Microprocessor and Digital Logic


• If the 7 bit hamming code received by receiver 1011011. Assume the even parity.
State whether the receiver code word is correct or wrong. If wrong locate the bit
having error.
• Soln first lets construct the 7 bit hamming

D7 D6 D5 P4 D3 P2 P1
1 0 1 1 0 1 1
• The Lets Check the parity P1= D3D5D7  1=011 it is Wrong. It is not even
parity it is odd parity so P1=1
• P2=D3D6D7  1=001 it is correct even parity so P=0
• P4= D5D6D71=101 It is Wrong. It is not even parity it is Odd parity so P4=1
• Lets concatenate( collectively ) P1P2P4  101 = 5
• So the fifth bit having error (D5) so it should correct by change the value D5 form 1 to
0
• So the correct data and parity stream will be 1001011

ECEG122 Microprocessor and Digital Logic


End

ECEG122 Microprocessor and Digital Logic

You might also like