You are on page 1of 45

Subtraction using rs complement 1. Add the minuend M to the rs 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 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.

Subtraction using (r-1)s complement


1.
2. 3. Add the minuend M to the (r-1)s complement of the subtrahend N. 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). 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 ( 9s complement of N) 1 69281 +1 end-around carry
69282 answer

(b)1s Complement Subtraction

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

Binary Addition (Direct)


Binary addition is very simple. This is best shown in an example of adding two binary numbers
1 1 1 1 1 1 1 0 1 + 1 0 1 1 1 --------------------1 0 1 0 1 0 0 1 1 1 carries

Binary Subtraction (Direct)


We can also perform subtraction (with borrows in place of carries). Lets subtract (10111)2 from (1001101)2

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.

Some commonly used Codes


1. 2. 3. 4. 5. Straight Binary Codes Natural BCD Codes Excess-3 Codes Gray Codes Alphanumeric Codes

Straight Binary Codes


One Binary Digit (one bit) can take on values 0, 1. This is used to represent numbers using natural( Straight) Binary form as discussed earlier (65)10 in straight binary represented by 1000001

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.

Natural BCD Codes


In this Codes, decimal digit 0 through 9 are represented by their natural binary equivalents using four bits and each 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 decimal digit similar to straight binary number system

Examples: (23)10 is represented by 0010 0011 (08)10 is represented by 0000 1000 (921)10 is represented by 1001 0010 0001

Putting It All Together

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.

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
Decimal
0 1 2 3 4 5 6 7 8 9

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

Excess-3 and 8,4,-2,-1 are self-complementing codes


Note that BCD is NOT self-complementing

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.

Construction of Gray Code


A 1-bit gray code has two code words 0 and 1 representing decimal numbers 0 and 1. An n-bit (n >=2) Gray Code will have first 2n-1 Gray Codes with n-1 bits (LSB) written in order with a leading 0 appended. The last 2n-1 Gray Codes with n-1 bits (LSB) written in reverse order( Mirror image) with a leading 1 appended.

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

More Examples: 3- bit Gray Code Decimal Number 0 1 2 3 4 5 6 7

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

Conversion From Binary to Gray


Start with the most significant bit of the binary number. 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

Conversion From Binary to Gray Cont

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

Gray code is not a number system.


It is an alternate way to represent four bit data

Only one bit changes from one decimal digit to the next Useful for reducing errors in communication. Can be scaled to larger numbers.

Direct Conversion From Gray to Binary

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 )

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

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?

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

Added even parity bit

Added odd parity bit

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 the message to make the total number of 1s either odd or even.

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.

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 be received 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

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.

Parity Generation for 4 bit data

You might also like