0% found this document useful (0 votes)
74 views103 pages

DLD UNIT I-Chkk

Uploaded by

Sariki Santosh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
74 views103 pages

DLD UNIT I-Chkk

Uploaded by

Sariki Santosh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 103

B.

Tech 2nd Year ECE-Sec-1-IIISem


Unit -1: Number Systems and Codes
Decimal, Binary, Octal, and Hexa-decimal
number systems and their conversions, ASCII
code, Excess-3 code, Gray code, Error
detection and correction, Parity generators
and checkers, Complement representation of
negative numbers.
 The technique to represent and work with
numbers is called number system.
 The number systems are used to quantify
the magnitude of something.
 The one way of representation of any
quantity is numerical (Digital).
Number
Systems

Decimal Binary Octal Hexadecimal


Number Number Number Number
System System System System
 Thedecimal system contains ten unique
symbols 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9.

 Decimal number system involves ten


symbols, that its base or radix is ten.

 The number system in which the weight


of each digit depends on its relative
position within the number, is called
positional number system.
 Any positional number system can be
expressed as sum of products of place value
and the digit value .

 dn dn-1 dn-2. . . . .d1 d0 . d-1 d-2 ….. d-m , then


the decimal equivalent is
(dn × 10n) + (dn-1 × 10n - 1) + . . . . . . .
+(d1 × 101) + (d0 × 100 ) + (d-1 × 10-1) + (d-2
× 10-2) . . . . .
Ex:
 The binary system contains two unique
symbols 0 and 1 .
 In Binary number system involves two
symbols, hence its base or radix is two.
 The number system in which the weight
of each digit depends on its relative
position within the number is called
positional number system.
 Any positional number system can be expressed
as sum of products of place value and the digit
value .
 dn dn-1 dn-2. . . . . d1 d0 . d-1 d-2 …… d-m the
binary equivalent is
(dn × 2n) + (dn-1 × 2n - 1) + . . . . . . . +(d1 ×
21) + (d0 × 20 ) + (d-1 × 2-1) + (d-2 × 2-2) . . . .
.
 The binary number system is used in digital
computers because the switching circuits used
in these computers use two-state devices such
as transistors, diodes, etc.
 The octal system contains ten unique
symbols 0, 1, 2, 3, 4, 5, 6 and 7.
 In octal number system involves eight
symbols, hence its base or radix is eight.

 dndn-1 dn-2. . . . . d1 d0 . d-1 d-2 .. d-m the


octal equivalent is
(dn × 8n) + (dn-1 × 8n - 1) + . . . . . . .
+(d1 × 81) + (d0 × 80 ) + (d-1 × 8-1) + (d-
2 × 8 ) . . . . .
-2
 The hexadecimal system contains ten
unique symbols 0, 1, 2, 3, 4, 5, 6, 7, 8,
9,A,B,C,D,E,F.
 In hexadecimal number system involves
sixteen symbols, hence its base or radix is
sixteen.
 dn dn-1 dn-2. . . . . d1 d0 . d-1 d-2 …. d-m the
hexadecimal equivalent is
(dn × 16n) + (dn-1 × 16n - 1) + . . . . . . .
+(d1 × 161) + (d0 × 160 ) + (d-1 × 16-1) +
(d-2 × 16-2) . . . . .
 In general two methods are followed for
number conversions:
 (a) Sum of weights method
 (b) Double dabble method – repetitive division by
‘b’ (for integers)or repetitive multiplication by
‘b’(for fractions).

 The number conversions can be done


between the available four number systems.

Decimal Binary
Octal
Hexadecimal
Binary Decimal
Octal
Hexadecimal

Octal Binary
Decimal
Hexadecimal

Binary
Hexadecimal
Octal
Decimal
Decimal to any ‘base-r’
Integer numbers: Divide the given decimal number
repeatedly by ‘r’ and collect the remainders. This
must continue until the integer quotient becomes
zero this method is called successive division.

EXAMPLES:
Fractional Numbers: First the given fraction number
multiplied by ‘r’ to give an integer and fraction, the new
fraction is multiplied again by ‘r’ to give a new integer
and a new fraction. This process continued until the
fraction becomes zero (or) until the number of digits has
sufficient accuracy (or) until the repetition of the
sequence is observed. The reminder should be written
from top to bottom.
EXAMPLES:
Decimal to Binary
Any ‘base-r’ to Decimal

 Theconversion from any base ‘r’ system


to decimal system is by the positional
weights methods or sum of weights
method.

Example 1:
Convert (10101)2 to decimal
(1 × 24) + (0 × 23) + (1 × 22) + (0 × 21) + (1
×20) = (21)10
Example 2:

Convert (A59C)16 to decimal = (42396)10


• 8 = 23
• Each group of 3 bits represents an octal digit

Octal Binary
0 000
1 001
2 010
3 011
4 100
5 101
6 110
7 111
EXAMPLE 1:

EXAMPLE 2:
• 16 = 24
• Each group of 4 bits represents a hexadecimal digit

Hex Binary
0 0000
1 0001
2 0010
3 0011
4 0100
5 0101
6 0110
7 0111
8 1000
9 1001
A 1010
B 1011
C 1100
D 1101
E 1110
F 1111
EXAMPLE 1:

EXAMPLE 2:
EXAMPLE:
EXAMPLE:
HEXADECIMAL- BINARY CONVERSION

EXAMPLE:
HEXADECIMAL-OCTAL CONVERSION

EXAMPLE:
Complete the conversion table
 Conversion between two bases other than decimal
can be done directly by using the procedures given;
however, the arithmetic operations would have to be
carried out using a base other than 10. It is generally
easier to convert to decimal first and then convert
the decimal number to the new base.
BINARY ADDITION

A B Carry Sum

0 0 0 0

0 1 0 1

1 0 0 1

1 1 1 0

Add the following number (1010)2 +(0001)2=(1011)2


11
1011
1011
10110
BINARY ADDITION
Add the following number (1101.101)2 +(111.011)2=(?)2
BINARY SUBTRACTION

A B Borrow Difference
0 0 0 0

0 1 1 1

1 0 0 1

1 1 0 0

Subtract the following number (1110)2 -(1010)2=(0100)2

1110
1010
0100
Binary division is similar to decimal division, except it is much easier
because the only two possible quotient digits are 0 and 1.
Convert the following numbers with the given radix to binary
(a) 4433(5) (b) 5654(7) (c) 1221(3)
COMPLEMENT REPRESENTATION OF NEGATIVE
NUMBERS

The complement representation of negative


numbers is done in 3 ways:

1. Sign magnitude numbers


2. 2’s compliment numbers
3. 1’s compliment numbers

Sign Magnitude numbers: In an n-bit sign and magnitude


system, a number is represented by a sign bit, 0 for
positive and 1 for negative, followed by n − 1 bits that
represent the magnitude of the number. With n − 1 bits the
magnitude can be 0 to 2(n−1) − 1.
The 2’s (or 1’s) complement system for representing signed
numbers works like this:

• If the number is positive, the magnitude is represented in its


true binary form and a sign bit 0 is placed in front of the MSB and
If the number is negative, the magnitude is represented in its 2’s
(or 1’s) complement form and a sign bit 1 is placed in front of the
MSB.
• The 2’s (or 1 ‘s) complement operation on a signed number will
change a positive number to a negative number and vice versa.
Example: A number 51 is represented in three number forms

(In sign magnitude form)


(In2’s complement form)
0 1 1 0 0 1 1 (In1’s complement form)
+51 In three forms, the
representation for +51 is
Sign bit Magnitude same as it is a positive
number.
1 1 1 0 0 1 1
-51 (In sign magnitude form)

Sign bit Magnitude

1 0 0 1 1 0 1
-51 (In2’s complement form)

Sign bit Magnitude


1 0 0 1 1 0 0
-51 (In1’s complement form)

Sign bit Magnitude


Characteristics of the 2’s complement numbers:
The 2’s complement numbers have the following properties:
1. There is one unique zero.
2. The 2’s complement of 0 is 0.
3. The left most bit cannot be used to express a quantity.
It is a sign bit. If it is a 1, the number is negative and if it is a 0, the
number is positive.
4. Significant information is contained in the Is of the positive
numbers and 0s of the negative numbers.
5. A negative number may be converted into a positive number by finding
its 2’s complement.
6. For an n-bit word which includes the sign bit and also there are (2n -1
-1) positive integers, 2n - 1 negative integers and one 0, for a total of 2n
unique states.
2’s complement numbers:
Express -45 in 8-bit 2’s complement form
+45 in 8 bit form is 00101101
Obtain the 1’s complement of 45 and add with 1
2’s complement numbers:
Express -73.75 in 12-bit 2’s complement form
+73.75 in 12 bit form is 010001001.1100
Obtain the 1’s complement of 73.75 and add with 1
Subtraction using 2’s complement :

Step1:Take 2’s complement of subtrahend and add it


to the minuend.

Step 2:If there is carry out, ignore it.

Step 3:Observe the MSB bit. If MSB is Zero result is


positive and is in true binary. If MSB is One
(irrespective of carry) result is negative in its 2’s
complement form.Take 2’s complement to find the
magnitude in binary.
Subtraction using 2’s complement :
Subtraction using 2’s complement :
Subtraction using 2’s complement :

Perform N1+N2, N1+(-N2) for the following 8-bit numbers


expressed in 2’s complement representation
N1=00110010 N2=11111101
Here N1=00110010 is positive=(+50)10
Here N2=11111101 is negative=(-3)10
Subtraction using 2’s complement :
1’s complement numbers:

Subtraction using 1’s complement :


Step1:Take 1’s complement of subtrahend and add it to
the minuend.
Step 2:If there is carry out, bring the carry around and
add it to the LSB
Step 3:If the MSB bit is Zero, then the result is positive
and is in true binary otherwise result is negative in its
1’s complement form is to be calculated to extract the
magnitude.
Subtraction using 1’s complement:
Subtraction using 1’s complement:
9’s complement and 10’s complement :
The 9’s complement of a decimal number is obtained by subtracting each
digit of that decimal number by 9

The 10’s complement of a decimal number is obtained by adding 1 to its


9’s complement

Find the 9’s complement of 3465 and 782.54 and its 10’s complement
9999
-3465
6534
10’s complement is 6534+1=6535
999.99
-782.54
217.45
10’s complement is 217.45+.01=217.46
9’s complement Subtraction :

Step 1:Take 9’s complement of subtrahend and add it


to the minuend.

Step 2:If there is carry out, indicates result is positive


otherwise negative.

Step 3:Add the carry to the LSD of this result to get


the answer, if there is no carry result is negative in its
9’s complement form.Take 9’s complement to find the
magnitude
9’s complement Subtraction :
10’s complement Subtraction :

Step 1:Take 10’s complement of subtrahend and add it


to the minuend.

Step 2:If there is carry out, indicates result is positive


otherwise negative.Here carry is ignored.

Step 3:if there is carry result is negative in its 10’s


complement form.Take 10’s complement to find the
magnitude
10’s complement Subtraction :
57
 It is an acronym for the Binary Coded Decimal exists from 0 to 9
 Example: 10:0001 0000
985:1001 1000 0101

BCD Addition:
• To add in BCD, add the BCD numbers by adding the 4-bit groups in
each column starting from the LSD.
• If there is no carry out from the addition of any of the 4-bit groups,
the sum term is a illegal code.
• If there is carry out from the addition of any of the 4-bit groups, add
0011 from the sum term of those groups (to skip illegal states).

58
59
BCD Subtraction:
• To subtract in BCD, add the BCD numbers by adding the 4-bit groups in
each column starting from the LSD.
• If there is no borrow out from the subtraction of any of the 4-bit groups,
the sum term is not a legal code
• If there is borrow out from the subtraction of any of the 4-bit groups,
subtract 0011 from the difference term of those groups (to skip illegal
states).

60
61
The alphanumeric codes are used to encode
the characters along with decimal numbers.
These are popularly used in I/O devices like
printers, keyboards, display terminals, etc.

The popularly used alphanumeric codes are:


 ASCII Code (7 bits = 27=128 unique symbols)
 EBCDIC Code (8 bits = 28=256 unique symbols)

These include alphabets, special symbols and


decimal digits
 It is an acronym for the American Standard Code for
Information Interchange.
 It is a standard seven-bit code that was first proposed
by the American National Standards Institute or ANSI in
1963, and finalized in 1968 as ANSI Standard X3.4. This
is a character encoding standard for electronic
communication. ASCII codes represent text in
computers, telecommunication equipment and other
devices.
 The purpose of ASCII was to provide a standard to code
various symbols ( visible and invisible symbols)
 In the ASCII character set, each binary value between
0 and 127 represents a specific character.
 Most computers extend the ASCII character set to use
the full range of 256 characters available in a byte.
The upper 128 characters handle special things like
accented characters from common foreign languages.
• ASCII is a character encoding scheme that encodes 128
different characters into 7 bit integers
• Computers can only read numbers, so ASCII is a
numerical representation of special characters
•Ex: ‘%’ ‘!’ ‘?’

ASCII has some interesting properties:


•Digits 0 to 9 span Hexadecimal values 3016 to 3916
•Upper case A-Z span 4116 to 5A16
•Lower case a-z span 6116 to 7A16
 Extended Binary Coded Decimal Interchange Code. Mainly
used in large computers etc.
The excess-3 codes are obtained as follows:
• To add in XS-3, add the XS-3 numbers by adding the 4-bit
groups in each column starting from the LSD.
• If there is no carry out from the addition of any of the 4-
bit groups, subtract 0011 from the sum term of those
groups (because when two decimal digits are added in XS-
3 and there is no carry, the result is in XS-6).
• If there is a carry out, add 0011 to the sum term of those
groups (because when there is a carry, the invalid states
are skipped and the result is in normal binary).
70
71
• To subtract in XS-3, subtract the XS-3 numbers by subtracting

each 4-bit group of the subtractend from the corresponding 4-bit


group of the minuend starting from the LSD.
• If there is no borrow from the next 4-bit group, add 0011 to the
difference term of such groups (because when decimal digits are
subtracted in XS-3 and there is no borrow, the result is in normal
binary).
• If there is a borrow, subtract 0011 from the difference term.

72
73
74
75
• When you count up or down in binary, the number of bit that
change with each digit change varies.
•From 0 to 1 just have a single but
•From 1 to 2 have 2 bits, a 1 to 0 transition and a 0 to 1
transition
•From 7 to 8 have 3 bits changing back to 0 and 1 bit changing to
a1
• For some applications multiple bit changes can cause significant
problems.
The decimal equivalent of gray code is as follows:
78
ADVANTAGE OF GRAY CODE
The advantage is that only bit in the code group changes in
going from one number to the next.
1)Error detection
2)Representation of analog data
3)Low power design

79
GRAY and BINARY conversions
BINARY TO GRAY
Find the gray code Find the Binary
Gn=Bn for the Binary code for the Gray
Gn-1=Bn ⊕ Bn-1 number 1010 code is 1010
Gn-2=Bn-1 ⊕ Bn-2
G4=B4 B4=G4
..
G1=B2 ⊕ B1 G3=B4 ⊕ B3 B3=B4 ⊕ G3
G2=B3 ⊕ B2 B2=B3 ⊕ G2
G1=B2 ⊕ B1 B1=B2 ⊕ G1
GRAY TO BINARY So, G4= 1 B4=1
G3=1 ⊕ 0 =1 B3=1 ⊕ 0 = 1
Bn=Gn G2= 0 ⊕ 1=1 B2=1 ⊕ 1 = 0
Bn-1=Bn ⊕ Gn-1 G1=1 ⊕ 0=1 B1=0 ⊕ 0 = 0
Bn-2=Bn-1 ⊕ Gn-2 Gray code is 1111 Binary code is 1100
..
B1=B2 ⊕ G1

80
• When a binary data is transmitted and processed, it is
susceptible to noise that can alter or distort its contents.
• The is may get changed to 0s and 0s to 1s. Because digital
systems must be accurate to the digit, errors can pose a serious
problem.
• Several schemes have been devised to detect the occurrence
of a single-bit error in a binary word, so that whenever such an
error occurs the concerned binary word can be corrected and
retransmitted.

81
PARITY
The simplest technique for detecting errors is that of adding an extra
bit, known as the parity bit, to each word being transmitted.

PARITY

ODD EVEN
PARITY PARITY
82
ODD PARITY
For odd parity, the parity bit is set to a 0 or a 1 at the
transmitter such that the total number of 1 bits in the
word including the parity bit is an odd number.

EVEN PARITY

For even parity, the parity bit is set to a 0 or a 1 at the


transmitter such that the total number of 1 bits in the
word including the parity bit is an even number.

83
PARITY GENERATOR
• A parity generator is a combinational logic circuit that
generates the parity bit in the transmitter.
• A combined circuit or devices of parity generators and
parity checkers are commonly used in digital systems to
detect the single bit errors in the transmitted data
word.
• The basic principle involved in the implementation of
parity circuits is that sum of odd number of 1s is always
1 and sum of even number of 1s is always zero.

84
ODD PARITY
The number of 1-bit must add up to an odd
number.

LOGIC DIAGRAM:

85
EVEN PARITY
The number of 1-bit must add up to an even
number.

LOGIC DIAGRAM:

86
PARITY CHECKER
• Parity checking uses parity bits to check that data has been
transmitted accurately.
• The parity bit is added to every data unit (typically seven
or eight bits) that are transmitted.
• The parity bit for each unit is set so that all bytes have
either an odd number or an even number of set bits.

87
PARITYGENERATOR/CHECKER
APPLICATIONS
• One important application of the use of an Exclusive-OR gate is to
generate parity.
• Parity is used to detect errors in transmitted data caused by noise or
other disturbances.
• A parity bit is an extra bit that is added to a data word and can be
either odd or even parity.
• In an even parity system, the sum of all the bits (including the parity
bit) is an even number. In an odd parity system the sum of all the bits
must be an odd number.

88
ERROR CORRECTION

• A code is said to be an error-correcting code, if the


correct code word can always be deduced from an
erroneous word.
• For a code to be a single-bit error-correcting code,
the minimum distance of that code must be three.
• The minimum distance of a code is the smallest
number of bits by which any two code words must
differ.

89
7-BIT HAMMING CODE:
• To transmit four data bits, three parity bits
located at positions 20, 21, and 22 are added to
make a 7-bit code word which is then transmitted.
The word format would be as shown below: Syndrome Table

• P1 P2 D3 P4 D5 D6 D7 where the D bits are the data


bits and the P bits are the parity bits. P1 is set to a
0 or 1 so that it establishes even parity over bits 1,
3, 5, and 7 (P1 D3 D5 D7).
• P2 is set to a O or a 1 to establish even parity over bits
2, 3, 6 and 7 (P2 D3 D6 D7). P4 is set to a 0 or a 1 to
establish even parity over bits 4, 5, 6, and 7 (P4 D5 D6
D7).

90
Decimal digit Hamming code bits
D7 D6 D5 P4 D3 P2 P1

0 0 0 0 0 0 0 0

1 0 0 0 0 1 1 1

2 0 0 1 1 0 0 1

3 0 0 1 1 1 1 0

4 0 1 0 1 0 1 0

5 0 1 0 1 1 0 1

6 0 1 1 0 0 1 1

7 0 1 1 0 1 0 0

8 1 0 0 1 0 1 1

9 1 0 0 1 1 0 91
0
7-BIT HAMMING CODE:
• Encode the data bits 1101 into 7 bit even parity Hamming code
P1 P2 D3 P4 D5 D6 D7
1 1 0 1
For P1(1,3,5,7) =(P1 111) must have even parity So P1 =1
For P2(2,3,6,7) =(P2 101) must have even parity So P2 =0
For P4(4,5,6,7) =(P4 101) must have even parity So P4 =0

Therefore the final code is 1010101

92
7-BIT HAMMING CODE:
• The message 1001001 coded in the 7-bit hamming code is
transmitted through a noisy channel, Decode the message
assuming the single error occurred in code word with even parity.
P1 P2 D3 P4 D5 D6 D7
1 0 0 1 0 0 1
For (1,3,5,7) =( 1001) has even parity So c1 =0
For (2,3,6,7) =(0001) must have even parity So error c2 =1
For (4,5,6,7) =(1001) has even parity So c3 =0
Therefore the error word is c3 c2 c1=010

As the error word is c3 c2 c1=010, complement 2nd bit from the


left. So the corrected code is 1101001

93
12-BIT HAMMING CODE:
• To transmit eight data bits, four parity bits located at positions
20, 21, 22 and 23 are added to make a 12-bit code word which is
then transmitted. The word format would be as shown below:
• P1 P2 D3 P4 D5 D6 D7 P8 D9 D10 D11 D12 where the D bits are the data
bits and the P bits are the parity bits. P1 is set to a 0 or 1 so that
it establishes even parity over bits 1, 3, 5, 7,9,11 (P1 D3 D5 D7
D9 D11).
• P2 is set to a O or a 1 to establish even parity over bits 2, 3, 6,7,10
and 11 (P2 D3 D6 D7 D10 D11).
• P4 is set to a 0 or a 1 to establish even parity over bits 4, 5, 6, 7 and
12 (P4 D5 D6 D7 D12).
• P8 is set to a 0 or a 1 to establish even parity over bits 8,9,10,11 and
12 (P8 D9 D10 D11 D12).
94
12-BIT HAMMING CODE:

95
12-BIT HAMMING CODE:
• Encode the data bits 01011011 into 12 bit even parity Hamming
code
P1 P2 D3 P4 D5 D6 D7 P8 D9 D10 D11 D12
0 1 0 1 1 0 1 1

For P1(1, 3, 5, 7,9,11 ) =(P101111) has even parity So P1 =0


For P2(2, 3, 6,7,10 11 ) =(P2 00101) must have even parity So P2 =0
For P4(4, 5, 6,7,12) =(P4 1011) must have even parity So P4 =1
For P8(8,9,10,11 and 12 ) =(P81011 ) must have even parity So P8 =1

Therefore the final code is 0001101110111

96
15-BIT HAMMING CODE:

• To transmit eleven data bits, four parity bits located at


positions 20, 21, 22 and 23 are added to make a 15-bit code word
which is then transmitted. The word format would be as shown
below:
• P1 P2 D3 P4 D5 D6 D7 P8 D9 D10 D11 D12 D13 D14 D15 where the D bits
are the data bits and the P bits are the parity bits. P1 is set to a
0 or 1 so that it establishes even parity over bits 1, 3, 5,
7,9,11,13,15 (P1 D3 D5 D7 D9 D11 D13 D15).

97
15-BIT HAMMING CODE:

• P2 is set to a O or a 1 to establish even parity over bits 2, 3,


6,7,10,11, 14,15 (P2 D3 D6 D7 D10 D11 D14 D15).
• P4 is set to a 0 or a 1 to establish even parity over bits 4, 5, 6,
7,12, 13,14,15 (P4 D5 D6 D7 D12 D13 D14 D15).
• P8 is set to a 0 or a 1 to establish even parity over bits
8,9,10,11,12,13,14,15 (P8 D9 D10 D11 D12 D13 D14 D15).

98
15-BIT HAMMING CODE:

99
15-BIT HAMMING CODE:
• The message 101001011101011 coded in the 15-bit hamming
code is transmitted through a noisy channel, Decode the message
assuming the single error occurred in code word with even parity.

P1 P2 D3 P4 D5 D6 D7 P8 D9 D10 D11 D12 D13 D14 D15


1 0 1 0 0 1 0 1 1 1 0 1 0 1 1

For (1,3,5,7,9,11,13,15) =( 11001001) has even parity So c1 =0


For (2,3,6,7,10,11,14,15) =(01101011) must have even parity So
error c2 =1
For (4,5,6,7,12,13,14,15) =(00101011) has even parity So c3 =0

100
15-BIT HAMMING CODE:

For (8,9,10,11,12,13,14,15) =(11101011) has even parity So c4 =0

Therefore the error word is c4c3 c2 c1=0010. So complement 2nd


bit from the left.
So the corrected code is 111001011101011

101
Refernces
1. http://www.trytoprogram.com/cpp-examples/cplusplus-binary-decimal-program
2. https://javacodekorner.blogspot.com/2018/12/decimal-to-octal-in-java.html

102

You might also like