0% found this document useful (0 votes)
6 views37 pages

Exercise 2

The document provides an overview of number systems and codes used in digital systems, including binary, octal, and hexadecimal representations. It discusses the advantages and disadvantages of digital systems compared to analog systems, as well as methods for converting between different number bases. Additionally, it covers the representation of signed numbers, including the use of complements for arithmetic operations.

Uploaded by

Joyce Labosta
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)
6 views37 pages

Exercise 2

The document provides an overview of number systems and codes used in digital systems, including binary, octal, and hexadecimal representations. It discusses the advantages and disadvantages of digital systems compared to analog systems, as well as methods for converting between different number bases. Additionally, it covers the representation of signed numbers, including the use of complements for arithmetic operations.

Uploaded by

Joyce Labosta
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

Module 2

CpE 8

UNIT - 1
NUMBER SYSTEMS & CODES

 Introduction about digital system


 Philosophy of number systems
 Complement representation of negative numbers
 Binary arithmetic
 Binary codes
 Error detecting & error correcting codes
 Hamming codes

INTRODUCTION ABOUT DIGITAL SYSTEM


A Digital system is an interconnection of digital modules and it is a system that manipulates discrete
elements of information that is represented internally in the binary form.

Now a day’s digital systems are used in wide variety of industrial and consumer products such as
automated industrial machinery, pocket calculators, microprocessors, digital computers, digital watches, TV
games and signal processing and so on.

Characteristics of Digital systems

 Digital systems manipulate discrete elements of information.


 Discrete elements are nothing but the digits such as 10 decimal digits or 26 letters of alphabets and
so on.
 Digital systems use physical quantities called signals to represent discrete elements.
 In digital systems, the signals have two discrete values and are therefore said to be binary.
 A signal in digital system represents one binary digit called a bit. The bit has a value either 0 or 1.

Analog systems vs Digital systems

Analog system process information that varies continuously i.e; they process time varying signals
that can take on any values across a continuous range of voltage, current or any physical parameter.

Digital systems use digital circuits that can process digital signals which can take either 0 or 1 for
binary system.

1
2
Advantages of Digital system over Analog system

1. Ease of programmability

The digital systems can be used for different applications by simply changing the program without
additional changes in hardware.

2. Reduction in cost of hardware

The cost of hardware gets reduced by use of digital components and this has been possible due to
advances in IC technology. With ICs the number of components that can be placed in a given area of Silicon
are increased which helps in cost reduction.

3. High speed

Digital processing of data ensures high speed of operation which is possible due to advances in
Digital Signal Processing.

4. High Reliability

Digital systems are highly reliable one of the reasons for that is use of error correction codes.

5. Design is easy

The design of digital systems which require use of Boolean algebra and other digital techniques is
easier compared to analog designing.

6. Result can be reproduced easily

Since the output of digital systems unlike analog systems is independent of temperature, noise,
humidity and other characteristics of components the reproducibility of results is higher in digital systems
than in analog systems.

Disadvantages of Digital Systems

 Use more energy than analog circuits to accomplish the same tasks, thus producing more heat as
well.
 Digital circuits are often fragile, in that if a single piece of digital data is lost or misinterpreted the
meaning of large blocks of related data can completely change.
 Digital computer manipulates discrete elements of information by means of a binary code.
 Quantization error during analog signal sampling.

3
NUMBER SYSTEM

Number system is a basis for counting varies items. Modern computers communicate and operate
with binary numbers which use only the digits 0 &1. Basic number system used by humans is Decimal
number system.

For Ex: Let us consider decimal number 18. This number is represented in binary as 10010.

We observe that binary number system take more digits to represent the decimal number. For large
numbers we have to deal with very large binary strings. So this fact gave rise to three new number systems.

i) Octal number systems

ii) Hexa Decimal number system

iii) Binary Coded Decimal number(BCD) system

To define any number system we have to specify

 Base of the number system such as 2,8,10 or 16.

 The base decides the total number of digits available in that number system.

 First digit in the number system is always zero and last digit in the number system is always
base-1.

Binary number system:

The binary number has a radix of 2. As r = 2, only two digits are needed, and these are 0 and 1. In
binary system weight is expressed as power of 2.

The left most bit, which has the greatest weight is called the Most Significant Bit (MSB). And the
right most bit which has the least weight is called Least Significant Bit (LSB).

4
For Ex: 1001.012 = [ ( 1 ) × 23 ] + [ ( 0 ) × 22 ] + [ ( 0 ) × 21 ] + [ ( 1 ) × 20 ] + [ ( 0 ) × 2-1 ] + [
( 1 ) × 22 ]
1001.012 = [ 1 × 8 ] + [ 0 × 4 ] + [ 0 × 2 ] + [ 1 × 1 ] + [ 0 × 0.5 ] + [ 1 × 0.25 ]
1001.012 = 9.2510

Decimal Number system

The decimal system has ten symbols: 0,1,2,3,4,5,6,7,8,9. In other words, it has a base of 10.

Octal Number System

Digital systems operate only on binary numbers. Since binary numbers are often very long, two
shorthand notations, octal and hexadecimal, are used for representing large binary numbers. Octal systems
use a base or radix of 8. It uses first eight digits of decimal number system. Thus it has digits from 0 to 7.

Hexa Decimal Number System

The hexadecimal numbering system has a base of 16. There are 16 symbols. The decimal digits 0 to
9 are used as the first ten digits as in the decimal system, followed by the letters A, B, C, D, E and F, which
represent the values 10, 11,12,13,14 and 15 respectively.

Decima Binar Octal Hexadeci


l y mal
0 0000 0 0
1 0001 1 1
2 0010 2 2
3 0011 3 3
4 0100 4 4
5 0101 5 5
6 0110 6 6
7 0111 7 7
8 1000 10 8
9 1001 11 9
10 1010 12 A
11 1011 13 B
12 1100 14 C
13 1101 15 D
14 1110 16 E
15 1111 17 F

5
Number Base conversions

The human beings use decimal number system while computer uses binary number system.
Therefore it is necessary to convert decimal number system into its equivalent binary.

i) Binary to octal number conversion


ii) Binary to hexa decimal number conversion

iii) Octal to binary Conversion

iv) Hexa to binary conversion

v) Octal to Decimal conversion

Ex: convert 4057.068 to octal

=4x83+0x82+5x81+7x80+0x8-1+6x8-2

6
=2048+0+40+7+0+0.0937

7
=2095.093710

vi) Decimal to Octal Conversion

Ex: convert 378.9310 to octal

37810 to octal: Successive division:

8 | 378
|
8 |47 --- 2
|
8 |5 --- 7 ↑
|
0 --- 5

=5728

0.9310 to octal :
0.93x8=7.44
0.44x8=3.52 ↓
0.53x8=4.16
0.16x8=1.28
=0.73418
378.9310=572.73418

vii) Hexadecimal to Decimal Conversion


Ex: 5C716 to decimal

=(5x162)+(C x161)+ (7 x160)

=1280+192+7

=14710
viii) Decimal to Hexadecimal Conversion

Ex: 2598.67510

1 6 2598
16 162 -6
10 -2

8
= A26 (16)

9
0.67510=0.675x16 -- 10.8
=0.800x16 -- 12.8 ↓
=0.800x16 -- 12.8
=0.800x16 -- 12.8
=0.ACCC16

2598.67510 = A26.ACCC16

ix) Octal to hexadecimal conversion:

The simplest way is to first convert the given octal no. to binary & then the binary no. to
hexadecimal.

Ex: 756.6038

7 5 6 . 6 0 3
111 101 110 . 110 000 011
0001 1110 1110 . 1100 0001 1000
1 E E . C 1 8

x) Hexadecimal to octal conversion:

First convert the given hexadecimal no. to binary & then the binary no. to octal.

Ex: B9F.AE16

B 9 F . A E
1011 1001 1111 . 1010 1110
101 110 011 111 . 101 011 100
5 6 3 7 . 5 3 4

=5637.534

Complements:

In digital computers to simplify the subtraction operation & for logical manipulation complements
are used. There are two types of complements used in each radix system.

i) The radix complement or r’s complement

10
ii) The diminished radix complement or (r-1)’s complement

11
Representation of signed no.s binary arithmetic in computers:

 Two ways of rep signed no.s


1. Sign Magnitude form
2. Complemented form
 Two complimented forms
1. 1‘s compliment form
2. 2‘s compliment form
Advantage of performing subtraction by the compliment method is reduction in the hardware.(
instead of addition & subtraction only adding ckt‘s are needed.)
i. e, subtraction is also performed by adders only.
Instead of subtracting one no. from other the compliment of the subtrahend is added to minuend.
In sign magnitude form, an additional bit called the sign bit is placed in front of the no. If the sign
bit is 0, the no. is +ve, If it is a 1, the no is _ve.

Ex:
0 1 0 1 0 0 1


Sign bit =+41 magnitude

1 1 0 1 0 0 1

= -41
Note: manipulation is necessary to add a +ve no to a –ve no

Representation of signed no.s using 2’s or 1’s complement method:


If the no. is +ve, the magnitude is rep in its true binary form & a sign bit 0 is placed in front
of the MSB.I f the no is _ve , the magnitude is rep in its 2‘s or 1‘s compliment form &a sign bit 1
is placed in front of the MSB.

Ex:

Given no. Sign mag form 2‘s comp form 1‘s comp form
01101 +13 +13 +13
010111 +23 +23 +23
10111 -7 -7 -8
1101010 -42 -22 -21

12
Special case in 2’s comp representation:
Whenever a signed no. has a 1 in the sign bit & all 0‘s for the magnitude bits, the decimal
equivalent is -2n , where n is the no of bits in the magnitude .
Ex: 1000= -8 & 10000=-16

Characteristics of 2’s compliment no.s:


Properties:
1. There is one unique zero
2. 2‘s comp of 0 is 0
3. The leftmost bit can‘t be used to express a quantity . it is a 0 no. is +ve.
4. For an n-bit word which includes the sign bit there are (2n-1-1) +ve integers,
2n-1 –ve integers & one 0 , for a total of 2n uniquestates.
5. Significant information is containd in the 1‘s of the +ve no.s & 0‘s of the _ve
no.s
6. A _ve no. may be converted into a +ve no. by finding its 2‘s comp.

Signed binary numbers:

Decimal Sign 2‘s comp form Sign 1‘s comp form Sign mag form
+7 0111 0111 0111
+6 0110 0110 0110
+5 0101 0101 0101
+4 0100 0100 0100
+3 0011 0011 0011
+2 0010 0010 0010
+1 0011 0011 0011
+0 0000 0000 0000

-0 -- 1111 1000
-1 1111 1110 1001
-2 1110 1101 1010
-3 1101 1100 1011
-4 1100 1011 1100
-5 1011 1010 1101
-6 1010 1001 1110
-7 1001 1000 1111
8 1000 -- --

13
Methods of obtaining 2’s comp of a no:

 In 3 ways
1. By obtaining the 1‘s comp of the given no. (by changing all 0‘s to 1‘s & 1‘s to 0‘s) &
then adding 1.
2. By subtracting the given n bit no N from 2n
3. Starting at the LSB , copying down each bit upto & including the first 1 bit
encountered , and complimenting the remaining bits.
Ex: Express -45 in 8 bit 2‘s comp form

+45 in 8 bit form is 00101101

I method:
1‘s comp of 00101101 & the add 1
00101101
11010010
+1
_ _ _ _ _ _ _ _ _ _

11010011 is 2‘s comp form


II method:

Subtract the given no. N from 2n

2n = 100000000
Subtract 45= -00101101
+1
__ _

11010011 is 2‘s comp

III method:

Original no: 00101101


Copy up to First 1 bit 1
Compliment remaining : 1101001

bits 11010011

14
Ex:

15
-73.75 in 12 bit 2‘s comp form
I method
01001001.1100
10110110.0011
+1

10110110.0100 is 2‘s

II method:
28 = 100000000.0000
Sub 73.75=-01001001.1100

10110110.0100 is 2‘s comp


III method :

Orginalno : 01001001.1100
Copy up to 1‘st bit 100
Comp the remaining bits: 10110110.0

10110110.0100

2’s compliment Arithmetic:


 The 2‘s comp system is used to rep –ve no.s using modulus arithmetic . The word length
of a computer is fixed. i.e, if a 4 bit no. is added to another 4 bit no . the result will be only
of 4 bits. Carry if any , from the fourth bit will overflow called the Modulus arithmetic.
Ex:1100+1111=1011
 In the 2‘s compl subtraction, add the 2‘s comp of the subtrahend to the minuend . If there
is a carry out , ignore it , look at the sign bit I,e, MSB of the sum term .If the MSB is a 0,
the result is positive.& it is in true binary form. If the MSB is a ` ( carry in or no carry at
all) the result is negative.& is in its 2‘s comp form. Take its 2‘s comp to find its magnitude
in binary.

Ex:Subtract 14 from 46 using 8 bit 2‘s comp arithmetic:

+14 = 00001110
-14 = 11110010 2‘s comp

+46 = 00101110
-14 =+11110010 2‘s comp form of -14

16
17
-32 (1)00100000 ignore carry
Ignore carry , The MSB is 0 . so the result is +ve. & is in normal binary
form. So the result is +00100000=+32.

EX: Add -75 to +26 using 8 bit 2‘s comp arithmetic

+75 = 01001011
-75 =10110101 2‘s comp

+26 = 00011010
2‘s comp form of -75
-75 =+10110101

-49 11001111 No carry

No carry , MSB is a 1, result is _ve & is in 2‘s comp. The magnitude is 2‘s comp of
11001111. i.e, 00110001 = 49. so result is -49

Ex: add -45.75 to +87.5 using 12 bit arithmetic


+87.5 = 01010111.1000
-45.75=+11010010.0100

-41.75 (1)00101001.1100 ignore carry


MSB is 0, result is +ve. =+41.75

1’s compliment of n number:


• It is obtained by simply complimenting each bit of the no,.& also , 1‘s comp of a
no, is subtracting each bit of the no. form [Link] complemented value rep the –
ve of the original no. One of the difficulties of using 1‘s comp is its rep o f zero.
Both 00000000 & its 1‘s comp 11111111 rep zero.
• The 00000000 called +ve zero& 11111111 called –ve zero.

Ex: -99 & -77.25 in 8 bit 1‘s comp


+99 = 01100011
-99 = 10011100

+77.25 = 01001101.0100
-77.25 = 10110010.1011

1’s compliment arithmetic:


In 1‘s comp subtraction, add the 1‘s comp of the subtrahend to the minuend. If there is a
carryout , bring the carry around & add it to the LSB called the end around carry. Look at the
sign bit (MSB) . If this is a 0, the result is +ve & is in true binary. If the MSB is a 1 ( carry or no

18
carry ), the result is –ve & is in its is comp form .Take its 1‘s comp to get the magnitude inn binary.

19
Ex: Subtract 14 from 25 using 8 bit 1‘s EX: ADD -25 to +14

25 = 00011001 +14 = 00001110


-45 = 11110001 -25 =+11100110

+11 (1)00001010 -11 11110100

+1
No carry MSB =1
00001011 result=-ve=-1110
MSB is a 0 so result is +ve (binary )

=+1110

Binary codes

Binary codes are codes which are represented in binary system with modification from the original
ones.
Weighted Binary codes
Non Weighted Codes
Weighted binary codes are those which obey the positional weighting principles, each
position of the number represents a specific weight. The binary counting sequence is an
example.

Reflective Code

20
A code is said to be reflective when code for 9 is complement for the code for 0, and

21
so is for 8 and 1 codes, 7 and 2, 6 and 3, 5 and 4. Codes 2421, 5211, and excess-3 are
reflective, whereas the 8421 code is not.

Sequential Codes

A code is said to be sequential when two subsequent codes, seen as numbers in binary
representation, differ by one. This greatly aids mathematical manipulation of data. The 8421 and
Excess-3 codes are sequential, whereas the 2421 and 5211 codes are not.

Non weighted codes

Non weighted codes are codes that are not positionally weighted. That is, each position
within the binary number is not assigned a fixed value. Ex: Excess-3 code

Excess-3 Code

Excess-3 is a non weighted code used to express decimal numbers. The code derives its
name from the fact that each binary code is the corresponding 8421 code plus 0011(3).

Gray Code

The gray code belongs to a class of codes called minimum change codes, in which
only one bit in the code changes when moving from one code to the next. The Gray code
is non-weighted code, as the position of bit does not contain any weight. The gray code
is a reflective digital code which has the special property that any two subsequent
numbers codes differ by only one bit. This is also called a unit- distance code. In digital
Gray code has got a special place.

22
Binary to Gray Conversion

Gray Code MSB is binary code MSB.


Gray Code MSB-1 is the XOR of binary code MSB and MSB-1.
MSB-2 bit of gray code is XOR of MSB-1 and MSB-2 bit of binary code.
MSB-N bit of gray code is XOR of MSB-N-1 and MSB-N bit of binary code.

8421 BCD code ( Natural BCD code):

Each decimal digit 0 through 9 is coded by a 4 bit binary no. called natural binary codes.
Because of the 8,4,2,1 weights attached to it. It is a weighted code & also sequential . it is useful
for mathematical operations. The advantage of this code is its case of conversion to & from
decimal. It is less efficient than the pure binary, it require more bits.
Ex: 14→1110 in binary

But as 0001 0100 in 8421 ode.

The disadvantage of the BCD code is that , arithmetic operations are more complex than
they are in pure binary . There are 6 illegal combinations 1010,1011,1100,1101,1110,1111 in these
codes, they are not part of the 8421 BCD code system . The disadvantage of 8421 code is, the rules
of binary addition 8421 no, but only to the individual 4 bit groups.

BCD Addition:

It is individually adding the corresponding digits of the decimal no,s expressed in 4


bit binary groups starting from the LSD . If there is no carry & the sum term is not an illegal code
, no correction is needed .If there is a carry out of one group to the next group or if the sum term is
an illegal code then 610(0100) is added to the sum term of that group & the resulting carry is added
to the next group.

Ex: Perform decimal additions in 8421 code


(a)25+13
In BCD 25= 0010 0101
In BCD +13 =+0001 0011

38 0011 1000
No carry , no illegal code .This is the corrected sum

23
(b). 679.6 + 536.8
679.6 = 0110 0111 1001 .0110 in BCD
+536.8 = +0101 0011 0010 .1000 in BCD
_ __ _________________
1216.4 1011 1010 0110 . 1110 illegal codes
+0110 + 0011 +0110 . + 0110 add 0110 to each

(1)0001 (1)0000 (1)0101 . (1)0100 propagate carry


/ / / /
+1 +1 +1 +1

0001 0010 0001 0110 . 0100

1 2 1 6 . 4

BCD Subtraction:

Performed by subtracting the digits of each 4 bit group of the subtrahend the digits from
the corresponding 4- bit group of the minuend in binary starting from the LSD . if there is no
borrow from the next group , then 610(0110)is subtracted from the difference term of this group.

(a)38-15

In BCD 38= 0011 1000


In BCD -15 = -0001 0101

23 0010 0011
No borrow, so correct difference.

.(b) 206.7-147.8

206.7 = 0010 0000 0110 . 0111 in BCD


-147.8 = -0001 0100 0111 . 0110 in BCD
__ _______________ _
58.9 0000 1011 1110 . 1111 borrows are present
-0110 -0110 . -0110 subtract 0110

0101 1000 . 1001

24
BCD Subtraction using 9’s & 10’s compliment methods:

Form the 9‘s & 10‘s compliment of the decimal subtrahend & encode that no. in
the 8421 code . the resulting BCD no.s are then added.

EX: 305.5 – 168.8

305.5 = 305.5
-168.8= +83.1 9‘s comp of -168.8
_ _

(1)136.6
+1 end around carry
136.7 corrected difference
305.510 = 0011 0000 0101 . 0101
+831.110 = +1000 0011 0001 . 0001 9‘s comp of 168
_ _ _ ________________ _ .8 in BCD
+1011 0011 0110 . 0110 1011 is illegal code
+0110 add 0110

(1)0001 0011 0110 . 0110


+1 End around carry

0001 0011 0110 . 0111


= 136.7
Excess three(xs-3)code:

It is a non-weighted BCD code .Each binary codeword is the corresponding 8421 codeword
plus 0011(3).It is a sequential code & therefore , can be used for arithmetic operations..It is a self-
complementing code.s o the subtraction by the method of compliment addition is more direct in
xs-3 code than that in 8421 code. The xs-3 code has six invalid states 0000,0010,1101,1110,1111..
It has interesting properties when used in addition & subtraction.

Excess-3 Addition:

Add the xs-3 no.s by adding the 4 bit groups in each column starting from the LSD. If there
is no carry starting from the addition of any of the 4-bit groups , subtract 0011 from the sum term
of those groups ( because when 2 decimal digits are added in xs-3 & there is no carry , result 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 normal binary).

25
EX: 37 0110 1010
+28 +0101 1011
_ _ _ _ _ _ _ _ _ _

65 1011 (1)0101 carry generated


+1 propagate carry
_____ _

1100 0101 add 0011 to correct 0101 &


-0011 +0011 subtract 0011 to correct 1100

_______ _

1001 1000 =6510

Excess -3 (XS-3) Subtraction:

Subtract the xs-3 no.s by subtracting each 4 bit group of the subtrahend from the
corresponding 4 bit group of the minuend starting form 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 & there is no borrow , result is normal binary). I f there is a borrow , subtract
0011 from the differenceterm(b coz taking a borrow is equivalent to adding six invalid states ,
result is in xs-6)

Ex: 267-175

267 = 0101 1001 1010


-175= -0100 1010 1000
_ _ ___ ___

0000 1111 0010


+0011 -0011 +0011

0011 1100 +0011 =9210

26
Xs-3 subtraction using 9’s & 10’s compliment methods:
Subtraction is performed by the 9‘s compliment or 10‘s compliment
Ex:687-348 The subtrahend (348) xs -3 code & its compliment are:

9‘s comp of 348 = 651


Xs-3 code of 348 = 0110 0111 1011
1‘s comp of 348 in xs-3 = 1001 1000 0100
Xs=3 code of 348 in xs=3 = 1001 1000 0100

687 687
-348 → +651 9‘s compl of 348

339 (1)338
+1 end around carry
_

339 corrected difference in decimal

1001 1011 1010 687 in xs-3


+1001 1000 0100 1‘s comp 348 in xs-3
_ _______ __
_

27
(1)0010 (1)0011 1110 carry generated
⁄⁄
+1 +1 propagate carry
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _-

(1)0011 0010 1110


+1 end around carry
_____________ _

0011 0011 1111 (correct 1111 by sub0011 and


+0011 +0011 +0011 correct both groups of 0011 by
__ _ ____ _ _ _ adding 0011)
__

0110 0110 1100 corrected diff in xs-3 = 33010

The Gray code (reflective –code):

Gray code is a non-weighted code & is not suitable for arithmetic operations. It is not a
BCD code . It is a cyclic code because successive code words in this code differ in one bit position
only i.e, it is a unit distance [Link] of the unit distance [Link] is also a reflective code i.e,both
reflective & unit distance. The n least significant bits for 2n through 2n+1-1 are the mirror images
of thosr for 0 through [Link] N bit gray code can be obtained by reflecting an N- 1 bit code about
an axis at the end of the code, & putting the MSB of 0 above the axis & the MSB of 1 below the
axis.
Reflection of gray codes:

Gray Code
1 bit 2 bit 3 bit 4 bit Decimal 4 bit binary
0 00 000 0000 0 0000
1 01 001 0001 1 0001
11 011 0011 2 0010
10 010 0010 3 0011
110 0110 4 0100
111 0111 5 0101
101 0101 6 0110
110 0100 7 0111

28
1100 8 1000
1101 9 1001
1111 10 1010
1110 11 1011
1010 12 1100
1011 13 1101
1001 14 1110
1000 15 1111

Binary to Gray conversion:

N bit binary no is rep by Bn Bn-1 ------------- B1


Gray code equivalent is by Gn Gn-1 ------------- G1
Bn,, Gn are the MSB‘s then the gray code bits are obtaind from the binary code as

Gn=Bn Gn-1=Bn Gn-2=Bn- ----------- G1=B2 B1


Bn-1 1 Bn-
→EX-or symbol

Procedure: ex-or the bits of the binary no with those of the binary no shifted one position to the
right . The LSB of the shifted no. is discarded & the MSB of the gray code [Link] the same as the
MSB of the original binaryno.

EX: 10001

(a). Binary : 1 →0 →0 →1

Gray : 1 1 0 1

(b). Binary: 1 0 0 1
Shifted binary: 1 0 0 (1)
______ _

1 1 0 1→gray

29
Gray to Binary Conversion:

If an n bit gray no. is rep by Gn Gn-1 -------------G1

its binary equivalent by Bn Bn-1-------------B1 then the binary bits are obtained from gray bits as

Bn= Gn Bn-1=Bn Gn-1 Bn-2= Gn-2 ----------- B1 =B2


G1

To convert no. in any system into given no. first convert it into binary & then binary to gray. To
convert gray no into binary no & convert binary no into require no system.

Ex:10110010(gray) = 110111002= DC16=3348=22010


EX:1101
Gray: 1 1 0 1

Binary:1 0 0 1

Ex: 3A716= 0011,1010,01112=1001110100(gray)


5278=101,011,0112=111110110(gray)
65210=10100011002= 1111001010(gray)

XS-3 gray code:

In a normal gray code , the bit patterns for 0(0000) & 9(1101) do not have a unit distance
between them i.e, they differ in more than one [Link] xs-3 gray code , each decimal digit is
encoded with gray code patter of the decimal digit that is greater by 3. It has a unit distance between
the patterns for 0 & 9.

XS-3 gray code for decimal digits 0 through 9

Decimal digit Xs-3 gray code Decimal digit Xs-3 gray code
0 0010 5 1100
1 0110 6 1101
2 0111 7 1111
3 0101 8 1110
4 0100 9 1010

30
Binary codes block diagram

Error – Detecting codes: When binary data is transmitted & processed,it is susceptible to noise
that can alter or distort its contents. The 1‘s may get changed to 0‘s & 1‘s .because digital systems
must be accurate to the digit, error can pose a 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 & retransmitted.

Parity: The simplest techniques for detecting errors is that of adding an extra bit known as parity
bit to each word being [Link] types of parity: Oddparity, evenparity forodd parity, the
parity bit is set to a ‗0‘ or a ‗1‘ at the transmitter such that the total no. of 1 bit in the word including
the parity bit is an odd [Link] even parity, the parity bit is set to a ‗0‘ or a ‗1‘ at the transmitter
such that the parity bit is an even no.

Decimal 8421 code Odd parity Even parity


0 0000 1 0
1 0001 0 1
2 0010 0 1
3 0011 1 0
4 0100 0 1
5 0100 1 0
6 0110 1 0
7 0111 0 1
8 1000 0 1
9 1001 1 0

31
When the digit data is received . a parity checking circuit generates an error signal if the
total no of 1‘s is even in an odd parity system or odd in an even parity system. This parity check
can always detect a single bit error but cannot detect 2 or more errors with in the same [Link]
parity is used more often than even parity does not detect the situation. Where all 0‘s are created
by a short ckt or some other fault condition.

Ex: Even parity scheme


(a) 10101010 (b) 11110110 (c)10111001
Ans:
(a) No. of 1‘s in the word is even is 4 so there is no error
(b) No. of 1‘s in the word is even is 6 so there is no error
(c) No. of 1‘s in the word is odd is 5 so there is error

Ex: odd parity


(a)10110111 (b) 10011010 (c)11101010

Ans:
(a) No. of 1‘s in the word is even is 6 so word has error
(b) No. of 1‘s in the word is even is 4 so word has error
(c) No. of 1‘s in the word is odd is 5 so there is no error

Checksums:

Simple parity can‘t detect two errors within the same word. To overcome this, use a sort of
2 dimensional parity. As each word is transmitted, it is added to the sum of the previously
transmitted words, and the sum retained at the transmitter end. At the end of transmission, the sum
called the check sum. Up to that time sent to the receiver. The receiver can check its sum with the
transmitted sum. If the two sums are the same, then no errors were detected at the receiver end. If
there is an error, the receiving location can ask for retransmission of the entire data, used in
teleprocessing systems.

Block parity:

Block of data shown is create the row & column parity bits for the data using odd parity.
The parity bit 0 or 1 is added column wise & row wise such that the total no. of 1‘s in each column
& row including the data bits & parity bit is odd as

32
Data Parity bit data
10110 0 10110
10001 1 10001
10101 0 10101
00010 0 00010
11000 1 11000
00000 1 00000
11010 0 11010

Error –Correcting Codes:

A code is said to be an error –correcting code, if the 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 that code is the smallest no. of bits
by which any two code words must differ. A code with minimum distance of 3 can‘t only correct
single bit errors but also detect ( can‘t correct) two bit errors, The key to error correction is that
it must be possible to detect & locate erroneous that it must be possible to detect & locate
erroneous digits. If the location of an error has been determined. Then by complementing the
erroneous digit, the message can be corrected , error correcting , code is the Hamming code , In
this , to each group of m information or message or data bits, K parity checking bits denoted by
P1,P2,----------pk located at positions 2 k-1 from left are added to form an (m+k) bit code word.
To correct the error, k parity checks are performed on selected digits of each code word, & the
position of the error bit is located by forming an error word, & the error bit is then
complemented. The k bit error word is generated by putting a 0 or a 1 in the 2 k-1th position
depending upon whether the check for parity involving the parity bit Pk is satisfied or [Link]
positions & their corresponding values :

33
Error Position For 15 bit code For 12 bit code For 7 bit code
C4 C3 C2 C1 C4 C3 C2 C1 C3 C2 C1
0 0000 0000 000
1 0001 0001 001
2 0010 0010 010
3 0011 0011 011
4 0100 0100 100
5 0101 0101 101
6 0 1 10 0 1 10 1 10
7 0 1 1 1 0 1 1 1 1 1 1
8 1 0 0 0 1 0 0 0
9 1 0 0 1 1 0 0 1
10 1 0 1 0 1 0 1 0
11 1 0 1 1 1 0 1 1
12 1 1 0 0 1 1 0 0
13 1 1 0 1
14 1 1 1 0
15 1 1 1 1

7- bit Hamming code:

To transmit four data bits, 3 parity bits located at positions 20 21&22 from left are
added to make a 7 bit codeword which is then transmitted.

The word format

P1 P2 D3 P4 D5 D6 D7
D—Data bits P-
Parity bits

Decimal Digit For BCD For Excess-3


P1P2D3P4D5D6D7 P1P2D3P4D5D6D7
0 0 0 0 0 0 0 0 1 0 0 0 0 1 1
1 1 1 0 1 0 0 1 1 0 0 1 1 0 0
2 0 1 0 1 0 1 1 0 1 0 0 1 0 1
3 1 0 0 0 0 1 1 1 1 0 0 1 1 0
4 1 0 0 1 1 0 0 0 0 0 1 1 1 1
5 0 1 0 0 1 0 1 1 1 1 0 0 0 0
6 1 1 0 0 1 1 0 0 0 1 1 0 0 1
7 0 0 0 1 1 1 1 1 0 1 1 0 1 0

34
8 1 1 1 0 0 0 0 0 1 1 0 0 1 1
9 0 0 1 1 0 0 1 0 1 1 1 1 0 0

35
Ex: Encode the data bits 1101 into the 7 bit even parity Hamming Code
The bit pattern is
P1P2D3P4D5D6D7

1 1 0 1

Bits 1,3,5,7 (P1 111) must have even parity, so P1 =1


Bits 2, 3, 6, 7(P2 101) must have even parity, so P2 =0
Bits 4,5,6,7 (P4 101)must have even parity, so P4 =0
The final code is 1010101
EX: Code word is 1001001
Bits 1,3,5,7 (C1 1001) →no error →put a 0 in the 1‘s position→C1=0
Bits 2, 3, 6, 7(C2 0001)) → error →put a 1 in the 2‘s position→C2=1
Bits 4,5,6,7 (C4 1001)) →no error →put a 0 in the 4‘s position→C3=0
15-bit Hamming Code: It transmit 11 data bits, 4 parity bits located 20 21 22 23
Word format is
P1 P2 D3 P4 D5 D6 D7 P8 D9 D10 D11 D12 D13 D14 D15

12-Bit Hamming Code:It transmit 8 data bits, 4 parity bits located at position 20 21 22 23
Word format is
P1 P2 D3 P4 D5 D6 D7 P8 D9 D10 D11 D12

Alphanumeric Codes:

These codes are used to encode the characteristics of alphabet in addition to the decimal
digits. It is used for transmitting data between computers & its I/O device such as printers,
keyboards & video display [Link] modern alphanumeric codes are ASCII code &
EBCDIC code.

36
Questions:

Show your solution to the following problem.

1-18 Perform the arithmetic operations (+42) + (—13) and (—42) — (—13) in binary using the
signed-2’s-complement representation for negative numbers.
1-19 The binary numbers listed have a sign in the leftmost position and, if negative, are in 2’s-
complement form. Perform the arithmetic operations indicated and verify the answers.
(a) 101011 + 111000
(b) 001110 + 110010
(c) 111001 - 001010
(d) 101011 - 100110
1-20 Represent the following decimal numbers in BCD: 13597; 93286; and 99880.
1-21 Determine the binary code for each of the ten decimal digits using a weighted code with weights
7, 4, 2, and 1.
1-22 The (r — l)’s complement of base-6 numbers is called the 5’s complement.
(a) Determine a procedure for obtaining the 5’s complement of base-6 numbers.
(b) Obtain the 5’s complement of (543210)6 -
(c) Design a 3-bit code to represent each of the six digits of the base-6 number system. Make the
binary code self-complementing so that the 5’s complement is obtained by changing 1 ’s to
0’s and 0’s to l’s in all the bits of the coded number.
1-23 Represent decimal number 8620 in (a) BCD, (b) excess-3 code, (c)2421 code, and (d) as a
binary number.
1-24 Represent decimal 3864 in the 2421 code of Table 1-2. Show that the code is self-
complementing by taking the 9’s complement of 3864.
1-25 Assign a binary code in some orderly manner to the 52 playing cards. Use the minimum
number of bits.
1-26 List the ten BCD digits with an even parity in the leftmost position. (Total of five bits per digit.)
Repeat with an odd-parity bit.
1-27 Write your full name in ASCII using an eight-bit code with the leftmost bit always 0. Include a
space between names and a period after a middle initial.
1-28 Decode the following ASCII code: 1001010 1101111 1101000 1101110 0100000 1000100
1101 111 1100101.
1-29 Show the bit configuration that represents the decimal number 295 (a) in binary, (b) in BCD,
and (c) in ASCII.

------------end of module------------

37

You might also like