Lect - 3 & 4
Lect - 3 & 4
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 rs complement of the number obtained in step 1 Case 1 M> = N M = 72532 and N= 03250 72532 + 96750 ( 10s complement of N) 1 69282 end carry discard it Answer : 69282
Case 2:M<N
Subtract 3250 72532 M=03250 N=72532 10s complement for N is 27468 So 03250 + 27468 _____________ 30718 (no carry) So answer will be (10s complement of 30718)= -69282
Given X= 1010100 and Y= 1000011, perform the subtraction (a) X-Y (b) Y-X using 2s complement (a) M=1010100 N=1000011 2s complement for N is 0111101 So 1010100 + 0111101 _____________ 10010001 Discard end carry, So answer will be 0010001.
(b) Y= 1000011 X= 1010100 So 1000011 + 0101100 _____________ 1101111 No end carry, Take 2s complement of answer and put ve sign. So answer will be -0010001.
(a) M = 72532 and N= 03250 72532 + 96749 ( 9s complement of N) 1 69281 +1 end-around carry
69282 answer
Using 1s complement numbers, subtracting numbers is also easy. For example, suppose we wish to subtract +(0001)2 from +(1100)2. Lets compute (12)10 - (1)10. (12)10 = +(1100)2 = 011002 in 1s comp. 0 1 1 0 0 (-1)10 = -(0001)2 = 111102 in 1s comp. 0 0 0 0 1
-------------0 1 1 0 0 1 1 1 1 0 Add + -------------nd Step 1: Take 1s complement of 2 operand 1 0 1 0 1 0 Step 2: Add binary numbers Add carry 1 Step 3: Add carry to low order bit -------------Final 0 1 0 1 1 Result
1s comp
1 0 10 10 1 0
10 0 0 10
borrows
0 1 1 0 1 1 0 1 1 1 -----------------------1 1 0 1 1 0
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
Example:
Multiply 1 0 0 1 by 1 1 0 1 1001 *1101 1001 0000* 1001** 1001*** 1110101
Codes
Computer and other digital circuits process data in the binary formats. Various binary codes are used to represent data which may be numeric, alphabets or special characters. A user must be very careful about the code being used while interpreting information available in the binary format.
Example:
1000001 represents (65)10 in straight binary 01000001 represents (41)10 in BCD. 1000001 represents A in ASCII Code.
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.
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 2N different values.(for example, 4 bits can represent 24 or 16 different values)N bits can take on unsigned decimal values from 0 to 2N-1.
Examples: (23)10 is represented by 0010 0011 (08)10 is represented by 0000 1000 (921)10 is represented by 1001 0010 0001
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 0101 672= 0110 0111 0010 +___ ___ ____ 1 0000 1101 0111 +0110+0110 +_________________ 0001 0110 0011 0111 (1637)10
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 1s complement of the coded number yields 9s complement of the number it self
Example: Excess 3 code of decimal 2 is 0101 its 1s complement is 1010 which is excess-3 code for decimal 7 , which is 9s complement of 2.
This property helps in performing subtraction operation in digital systems.
BCD 8,4,2,1
0000 0001 0010 0011 0100 0101 0110 0111 1000 1001
Excess-3 8,4,-2,-1
0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 0000 0111 0110 0101 0100 1011 1010 1001 1000 1111
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 from the preceding and the succeeding numbers by a single bit. It is not a weighted code. It is a reflected code.
Examples: 1 Bit Gray Code Decimal Number Gray Code 0 1 2 Bit Gray Code 0 1 2 3
0 1 0 0 1 1 0 1 1 0
Gary Code 0 0 0 0 0 1 0 1 1 1 1 1 1 0 1 0
0 1 1 0 0 1 1 0
Gray Code
Digit Binary 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111 Gray Code 0000 0001 0011 0010 0110 0111 0101 0100 1100 1101 1111 1110 1010 1011 1001 1000
Only one bit changes from one decimal digit to the next Useful for reducing errors in communication. Can be scaled to larger numbers.
Example:
Gray 1
Binary
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 9 and 26 alphabets A through Z , we need a minimum of 6-bits ( 26 = 64 ) not 5 bits
Frequently there is a need to represent more than 64 characters including the lower case letters 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 )
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
A
ASCII (bin)
1000001
ASCII (hex)
41
Decimal
65
Octal
101
B
C Z a 1
1000010
1000011
42
43
66
67
102
103
ASCII Codes
ASCII Codes
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. P
1 1 0 0 0 0 1 1
Information Bits
0 1 0 0 0 0 1 1
Odd parity to make total number of 1s odd ( including parity bit) Even parity to make total number of 1s even ( including parity bit) 1100 0001 is EBCDIC representation of alphabet A.
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 errordetecting code.
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).
Parity
Even parity: set parity bit to 0 if there are an even number of 1s in the code. Odd parity: set parity bit to 1 if there are an even number of 1s in the code.
Even-parity Odd-parity
1110
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.