Upload
shivam007
View
236
Download
0
Embed Size (px)
Citation preview
7/27/2019 Lect - 3 & 4.ppt
http://slidepdf.com/reader/full/lect-3-4ppt 1/45
1. Add the minuend M to the r’s complement of the subtrahend N.
2. Inspect the result obtained in step1 for an end carry
3. If an end carry occurs, discard it or
4. If end carry does not occur ,take the r’s complement of thenumber obtained in step 1
Case 1 M> = N
M = 72532 and N= 03250
72532
+ 96750 ( 10’s complement of N)
1 69282
end carry discard it
Answer : 69282
Subtraction using r’s complement
7/27/2019 Lect - 3 & 4.ppt
http://slidepdf.com/reader/full/lect-3-4ppt 2/45
Case 2:M<N
• Subtract 3250 – 72532M=03250 N=72532
10’s complement for N is 27468
So 03250+ 27468
_____________
30718 (no carry)So answer will be –(10’s complement of 30718)= -69282
7/27/2019 Lect - 3 & 4.ppt
http://slidepdf.com/reader/full/lect-3-4ppt 3/45
Given X= 1010100 and Y= 1000011, perform the
subtraction (a) X-Y (b) Y-X using 2’s complement
(a) M=1010100 N=1000011
2’s complement for N is 0111101
So 1010100
+ 0111101
_____________
10010001
Discard end carry, So answer will be 0010001.
7/27/2019 Lect - 3 & 4.ppt
http://slidepdf.com/reader/full/lect-3-4ppt 4/45
(b) Y= 1000011 X= 1010100
• So 1000011
+ 0101100
_____________
1101111 No end carry, Take 2’s complement of answer and put –
ve sign.
• So answer will be -0010001.
7/27/2019 Lect - 3 & 4.ppt
http://slidepdf.com/reader/full/lect-3-4ppt 5/45
Subtraction using (r-1)’s complement
1. Add the minuend M to the (r-1)’s complement of the subtrahend N. 2. Inspect the result obtained in step1 for an end carry if an end carry
occurs, add 1 to the least significant digit (end-around carry).
3. If end carry does not occur, take the (r-1)’s complement of the number obtained in step 1.
(a) M = 72532 and N= 03250
72532
+ 96749 ( 9’s complement of N)
1 69281
+1 end-around carry69282 answer
7/27/2019 Lect - 3 & 4.ppt
http://slidepdf.com/reader/full/lect-3-4ppt 6/45
(b)1’s Complement Subtraction
• Using 1’s complement numbers, subtracting numbers is also easy.
• For example, suppose we wish to subtract +(0001)2 from +(1100)2.
• Let’s compute (12)10 - (1)10.
– (12)10 = +(1100)2 = 011002 in 1’s comp.
– (-1)10 = -(0001)2 = 111102 in 1’s comp.0 1 1 0 0
- 0 0 0 0 1
--------------
0 1 1 0 0
+ 1 1 1 1 0
--------------
1 0 1 0 1 0
1
--------------
0 1 0 1 1
Add carry
Final
Result
Step 1: Take 1’s complement of 2nd operandStep 2: Add binary numbers
Step 3: Add carry to low order bit
1’s comp
Add
7/27/2019 Lect - 3 & 4.ppt
http://slidepdf.com/reader/full/lect-3-4ppt 7/45
Binary Addition (Direct)
• Binary addition is very simple.• This is best shown in an example of adding
two binary numbers…
1 1 1 1 0 1
+ 1 0 1 1 1
---------------------
0
1
0
1
1
1111
1 1 00
carries
7/27/2019 Lect - 3 & 4.ppt
http://slidepdf.com/reader/full/lect-3-4ppt 8/45
Binary Subtraction (Direct)° We can also perform subtraction (with borrows in place of
carries).° Let’s subtract (10111)2 from (1001101)2…
1 10
0 10 10 0 0 10
1 0 0 1 1 0 1
- 1 0 1 1 1
------------------------
1 1 0 1 1 0
borrows
7/27/2019 Lect - 3 & 4.ppt
http://slidepdf.com/reader/full/lect-3-4ppt 9/45
Binary Multiplication
• Binary Multiplication is similar to decimal
multiplication
• In binary each partial product is zero when
multiplication of (1 or 0 ) by 0.
• In binary each partial product is one when
multiplication of 1 by 1
7/27/2019 Lect - 3 & 4.ppt
http://slidepdf.com/reader/full/lect-3-4ppt 10/45
Example:
• Multiply 1 0 0 1 by 1 1 0 1
1 0 0 1
* 1 1 0 1
1 0 0 1
0 0 0 0 *
1 0 0 1 * *1 0 0 1 * * *
1 1 1 0 1 0 1
7/27/2019 Lect - 3 & 4.ppt
http://slidepdf.com/reader/full/lect-3-4ppt 11/45
Codes
• Computer and other digital circuits processdata in the binary formats.
• Various binary codes are used to representdata which may be numeric, alphabets or special characters.
• A user must be very careful about the code being used while interpreting informationavailable in the binary format.
7/27/2019 Lect - 3 & 4.ppt
http://slidepdf.com/reader/full/lect-3-4ppt 12/45
Example:
• 1000001 represents (65)10 in straight binary
• 01000001 represents (41)10 in BCD.
• 1000001 represents A in ASCII Code.
7/27/2019 Lect - 3 & 4.ppt
http://slidepdf.com/reader/full/lect-3-4ppt 13/45
Some commonly used Codes
1. Straight Binary Codes
2. Natural BCD Codes
3. Excess-3 Codes
4. Gray – Codes
5. Alphanumeric Codes
7/27/2019 Lect - 3 & 4.ppt
http://slidepdf.com/reader/full/lect-3-4ppt 14/45
Straight Binary Codes
• One Binary Digit (one bit) can take on values
0, 1.
• This is used to represent numbers usingnatural( Straight) Binary form as discussed
earlier
• (65)10
in straight binary represented by
1000001
7/27/2019 Lect - 3 & 4.ppt
http://slidepdf.com/reader/full/lect-3-4ppt 15/45
More Examples:-
• We can represent TWO values:
True = 1, False = 0
On = 1 , off = 0
• Two Binary digits (two bits) can take on
values of 00, 01, 10, 11.
7/27/2019 Lect - 3 & 4.ppt
http://slidepdf.com/reader/full/lect-3-4ppt 16/45
• Three Binary digits (three bits) can take on
values of 000, 001, 010, 011, 100, 101, 110,
111. We can represent 8 values
• N bits (or N binary Digits) can represent 2 N
different values.(for example, 4 bits can
represent 24 or 16 different values)N bits
can take on unsigned decimal values from 0to 2 N-1.
7/27/2019 Lect - 3 & 4.ppt
http://slidepdf.com/reader/full/lect-3-4ppt 17/45
Natural BCD Codes
• In this Codes, decimal digit 0 through 9 are represented by their natural binary equivalents using four bits andeach decimal digit of a decimal number is represented
by this four bits code individually
• It is also known as 8,4,2,1 code.
• 8,4,2,1 are the weights of the four bit of the decimaldigit similar to straight binary number system
7/27/2019 Lect - 3 & 4.ppt
http://slidepdf.com/reader/full/lect-3-4ppt 18/45
Examples:-
• (23)10 is represented by 0010 0011
• (08)10 is represented by 0000 1000
• (921)10 is represented by 1001 0010 0001
7/27/2019 Lect - 3 & 4.ppt
http://slidepdf.com/reader/full/lect-3-4ppt 19/45
Putting It All Together
7/27/2019 Lect - 3 & 4.ppt
http://slidepdf.com/reader/full/lect-3-4ppt 20/45
BCD Addition
Represent the unsigned decimal numbers 965 and 672 in BCD
and then show the steps necessary to form their sum .
965= 1001 0110 0101672= 0110 0111 0010
+___ ___ ____
1 0000 1101 0111
+0110+0110
+_________________ 0001 0110 0011 0111 (1637)10
7/27/2019 Lect - 3 & 4.ppt
http://slidepdf.com/reader/full/lect-3-4ppt 21/45
Excess-3 Codes
• This is another from of BCD Code , in which each
decimal digit is coded into a 4-bit binary code
• The code for each decimal digit is obtained by adding
decimal 3 to the BCD code of the digit.
• Decimal 2 is coded as 0010 + 0011= 0101
• It is not a weighted code
• It is a self complementing code, means 1’s complement
of the coded number yields 9’s complement of the
number it self
7/27/2019 Lect - 3 & 4.ppt
http://slidepdf.com/reader/full/lect-3-4ppt 22/45
Example:-
• Excess – 3 code of decimal 2 is 0101 its 1’s
complement is 1010 which is excess-3 code
for decimal 7 , which is 9’s complement of 2.
• This property helps in performing subtraction
operation in digital systems.
7/27/2019 Lect - 3 & 4.ppt
http://slidepdf.com/reader/full/lect-3-4ppt 23/45
Other Decimal Codes
• Many ways to assign 4-bit code to 10 decimal digits
• Each code uses only 10 combinations out of 16
• BCD and 8, 4, -2, -1 are
weighted codes
• Excess-3 and 8,4,-2,-1 are
self-complementing codes
• Note that BCD is NOTself-complementing
DecimalBCD
8,4,2,1Excess-3 8,4,-2,-1
0 0000 0011 0000
1 0001 0100 0111
2 0010 0101 0110
3 0011 0110 0101
4 0100 0111 01005 0101 1000 1011
6 0110 1001 1010
7 0111 1010 1001
8 1000 1011 1000
9 1001 1100 1111
7/27/2019 Lect - 3 & 4.ppt
http://slidepdf.com/reader/full/lect-3-4ppt 24/45
Gray Code
• It is a very useful code in which a decimal
number is represented in binary form in such a
way so that each gray code number differs fromthe preceding and the succeeding numbers by a
single bit.
• It is not a weighted code.• It is a reflected code.
7/27/2019 Lect - 3 & 4.ppt
http://slidepdf.com/reader/full/lect-3-4ppt 25/45
Construction of Gray Code
• A 1-bit gray code has two code words 0 and1 representing decimal numbers 0 and 1.
• An n-bit (n >=2) Gray Code will have first2n-1 Gray Codes with n-1 bits (LSB) writtenin order with a leading 0 appended.
• The last 2n-1 Gray Codes with n-1 bits (LSB)written in reverse order( Mirror image) witha leading 1 appended.
7/27/2019 Lect - 3 & 4.ppt
http://slidepdf.com/reader/full/lect-3-4ppt 26/45
Examples:-
• 1 Bit Gray Code
Decimal Number Gray Code
0 01 1
• 2 Bit Gray Code
0 0 0
1 0 1
2 1 1
3 1 0
7/27/2019 Lect - 3 & 4.ppt
http://slidepdf.com/reader/full/lect-3-4ppt 27/45
More Examples:-
• 3- bit Gray Code
Decimal Number Gary Code
0 0 0 0
1 0 0 12 0 1 1
3 0 1 0
4 1 1 0
5 1 1 1
6 1 0 1
7 1 0 0
7/27/2019 Lect - 3 & 4.ppt
http://slidepdf.com/reader/full/lect-3-4ppt 28/45
Conversion From Binary to Gray
• Start with the most significant bit of the binarynumber.
• Copy this bit as the MSB of the gray code
number.• Add the MSB of the binary to the next bit of
the binary number.• The sum (ignoring carry) is the next bit of the
gray code number.• Continue adding each bit of the binary to the
next bit to its right to get the gray code for that
position as shown in the next slide
7/27/2019 Lect - 3 & 4.ppt
http://slidepdf.com/reader/full/lect-3-4ppt 29/45
Conversion From Binary to Gray Cont…
d
7/27/2019 Lect - 3 & 4.ppt
http://slidepdf.com/reader/full/lect-3-4ppt 30/45
Gray Code
• Gray code is not a number
system. – It is an alternate way to represent four
bit data
• Only one bit changes fromone decimal digit to the
next
• Useful for reducing errorsin communication.
• Can be scaled to larger
numbers.
Digit Binary GrayCode
0 0000 0000
1 0001 0001
2 0010 0011
3 0011 0010
4 0100 0110
5 0101 0111
6 0110 0101
7 0111 0100
8 1000 1100
9 1001 1101
10 1010 1111
11 1011 1110
12 1100 1010
13 1101 1011
14 1110 1001
15 1111 1000
7/27/2019 Lect - 3 & 4.ppt
http://slidepdf.com/reader/full/lect-3-4ppt 31/45
Direct Conversion From Gray to Binary
Example:
Gray 1 1 0 0
1
Binary
1 0 0 0 1
7/27/2019 Lect - 3 & 4.ppt
http://slidepdf.com/reader/full/lect-3-4ppt 32/45
Alphanumeric Code
• In Many situations, digital systems are
required to handle data that may consist of
numerals, letters and special symbols• If we use an n-bit binary code, we can
represent 2n elements using this code
therefore to represent 10 digits 0 through 9and 26 alphabets A through Z , we need a
minimum of 6-bits ( 26 = 64 ) not 5 bits
7/27/2019 Lect - 3 & 4.ppt
http://slidepdf.com/reader/full/lect-3-4ppt 33/45
• Frequently there is a need to represent more
than 64 characters including the lower caseletters and the special control characters for
the transmission of the digital information
• For this reason the following two codes are
normally used
– Extended BCD Interchange ( EBCDIC )
– American Standard Code for Info. Interchange (
ASCII )
7/27/2019 Lect - 3 & 4.ppt
http://slidepdf.com/reader/full/lect-3-4ppt 34/45
American Standard Code for
Info. Interchange ( ASCII )
• Required to represent more than 64 characters
• 7- bit code word.
• Maximum128 characters different characters
can be represented by this code.
• 100 0001 is ASCII representation of alphabet A
ASCII C d
7/27/2019 Lect - 3 & 4.ppt
http://slidepdf.com/reader/full/lect-3-4ppt 35/45
ASCII Code• American Standard Code for Information Interchange
• ASCII is a 7-bit code, frequently used with an 8th bit for error
detection (more about that in a bit).
Character ASCII (bin) ASCII (hex) Decimal Octal
A 1000001 41 65 101
B 1000010 42 66 102
C 1000011 43 67 103
…
Z
a
…
1
‘
ASCII C d
7/27/2019 Lect - 3 & 4.ppt
http://slidepdf.com/reader/full/lect-3-4ppt 36/45
ASCII Codes
° ASCII Codes
° A – Z (26 codes), a – z (26 codes)
° 0-9 (10 codes), others (@#$%^&*….)
° Complete listing in Mano text
° Transmission susceptible to noise
° Typical transmission rates (1500 Kbps, 56.6 Kbps)
° How to keep data transmission accurate?
7/27/2019 Lect - 3 & 4.ppt
http://slidepdf.com/reader/full/lect-3-4ppt 37/45
Parity Codes• Parity codes are formed by concatenating a parity bit, P to
each code word of C.• In an odd-parity code, the parity bit is specified so that the
total number of ones is odd.
• In an even-parity code, the parity bit is specified so that the
total number of ones is even.
Information BitsP
1 1 0 0 0 0 1 1
Added even parity bit
0 1 0 0 0 0 1 1
Added odd parity bit
7/27/2019 Lect - 3 & 4.ppt
http://slidepdf.com/reader/full/lect-3-4ppt 38/45
Extended BCD Interchange ( EBCDIC )
• Also used to represent more than 64 characters
• 8- bit code word.
• 8th bit (MSB) is invariably added for parity.• Maximum128 characters different characters can
be represented by this code.
• A Parity bit is an extra bit included with themessage to make the total number of 1’s either odd or even.
7/27/2019 Lect - 3 & 4.ppt
http://slidepdf.com/reader/full/lect-3-4ppt 39/45
• Odd parity to make total number of 1’s odd
( including parity bit)
• Even parity to make total number of 1’s even
( including parity bit)
• 1100 0001 is EBCDIC representation of
alphabet A.
7/27/2019 Lect - 3 & 4.ppt
http://slidepdf.com/reader/full/lect-3-4ppt 40/45
Parity Bit & Error Detection• Information in form digital signals are transmitted
from one location (transmitter) to another location(receiver), transmission errors may occur because of electrical noise in the channel.
• Due to such error a signal transmitted as 0 may bereceived as 1 or vice-versa.
• It is desired to detect the error in the received data
word, locate its bit position and correct it.• Usually a probability of occurrence of error in at least
1 bit position is always there, so we restrict our discussion to the detection of single error
7/27/2019 Lect - 3 & 4.ppt
http://slidepdf.com/reader/full/lect-3-4ppt 41/45
• To ensure that the occurrence of single error does not lead
to incorrect interpretation at the receiver, the code used to
transmit the information should possess the property that
the occurrence of any single error is easily detected.
• This property could be achieved if an extra bit is attached
to the n- bit code word to make the number of bit as “n+1”in such a way so as to make a number of ones in the
resulting (n+1)-bit code even or odd, it will certainly a
error – detecting code.
7/27/2019 Lect - 3 & 4.ppt
http://slidepdf.com/reader/full/lect-3-4ppt 42/45
• For detection of error an extra bit known as
parity bit is attached to each code word to
make the number of ones in the code even(even parity) or odd ( odd parity).
7/27/2019 Lect - 3 & 4.ppt
http://slidepdf.com/reader/full/lect-3-4ppt 43/45
Parity
• Even parity: set parity bit to 0 if there are an
even number of 1’s in the code.
• Odd parity: set parity bit to 1 if there are aneven number of 1’s in the code.
Even-parity Odd-parity
1 1 1 0 1 0
7/27/2019 Lect - 3 & 4.ppt
http://slidepdf.com/reader/full/lect-3-4ppt 44/45
• Parity will not detect 2 bit errors because
changing 2 bits does not affect the parity.• Parity will detect ODD numbers of bit errors,
e.g, 1,3 etc.
• Note that 1 bit error are more likely than 2 bit
etc.