Exercise 2
Exercise 2
CpE 8
UNIT - 1
NUMBER SYSTEMS & CODES
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.
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.
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.
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.
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.
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.
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
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.
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.
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.
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.
=4x83+0x82+5x81+7x80+0x8-1+6x8-2
6
=2048+0+40+7+0+0.0937
7
=2095.093710
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
=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
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
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.
10
ii) The diminished radix complement or (r-1)’s complement
11
Representation of signed no.s binary arithmetic in computers:
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
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
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
I method:
1‘s comp of 00101101 & the add 1
00101101
11010010
+1
_ _ _ _ _ _ _ _ _ _
2n = 100000000
Subtract 45= -00101101
+1
__ _
III method:
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
Orginalno : 01001001.1100
Copy up to 1‘st bit 100
Comp the remaining bits: 10110110.0
10110110.0100
+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.
+75 = 01001011
-75 =10110101 2‘s comp
+26 = 00011010
2‘s comp form of -75
-75 =+10110101
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
+77.25 = 01001101.0100
-77.25 = 10110010.1011
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
+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 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
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
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:
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 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
23 0010 0011
No borrow, so correct difference.
.(b) 206.7-147.8
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.
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
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
_ _ _ _ _ _ _ _ _ _
_______ _
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
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:
687 687
-348 → +651 9‘s compl of 348
339 (1)338
+1 end around carry
_
27
(1)0010 (1)0011 1110 carry generated
⁄⁄
+1 +1 propagate carry
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _-
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
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:
its binary equivalent by Bn Bn-1-------------B1 then the binary bits are obtained from gray bits as
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.
Binary:1 0 0 1
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.
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.
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.
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
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
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.
P1 P2 D3 P4 D5 D6 D7
D—Data bits P-
Parity bits
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
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:
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