0% found this document useful (0 votes)
43 views20 pages

Lecture 4

The document discusses various binary codes and techniques for digital data representation and arithmetic operations including subtraction using 1's and 2's complement, binary coded decimal addition, Gray code, and error detection codes using parity bits. It provides examples of performing subtraction and addition on binary numbers, converting between binary and Gray codes, and assigning parity bits for error detection. The self tasks involve performing arithmetic on binary numbers, converting codes, and identifying errors using parity bits.

Uploaded by

Osama Rehman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views20 pages

Lecture 4

The document discusses various binary codes and techniques for digital data representation and arithmetic operations including subtraction using 1's and 2's complement, binary coded decimal addition, Gray code, and error detection codes using parity bits. It provides examples of performing subtraction and addition on binary numbers, converting between binary and Gray codes, and assigning parity bits for error detection. The self tasks involve performing arithmetic on binary numbers, converting codes, and identifying errors using parity bits.

Uploaded by

Osama Rehman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 20

Subtractions & Other Codes

Lecture # 4
Subtraction using 1’s & 2’s compliment
• A – B = A + (-B)

• Subtraction using 1’s compliment

1. Convert B into 1’s compliment


2. Then add A & (-B)
3. If the final carry is 1 add it to the result of
addition,& subtraction is positive.
4. If the final carry is 0 ,then the result is negative and
take its complement again.
Case 1
• Both positive ,A>B
• Perform 1011 – 0100 by 1’s complement.
• A =1011
• B= 0100
• B’=1011
• S= 10110
Self Task
• Using 1’s Complement,
– Perform X-Y if X = 1010100 and Y = 1000011

– Perform Y-X
Case 2
• Using 2’s Complement of following signed
numbers:
– Perform +6+13 ,

– Perform +6-13

– Perform -6-13
Binary Code

Digital data is represented in group of binary bits


called binary code.
Binary Coded Decimal
• It is numeric code in which each digit of
decimal number is represented by seperate
group of bits.
• Represent 0-9 decimal
• 5 0101
BCD Addition
• Having 3 cases
• Case 1: Sum equals to 9 or less with 0 carry
6+3=9
A= 0110 6
B= 0011 3
S= 1001 9
BCD Addition
• Case 2 : Sum greater than 9 with carry 0
– Add 6 bits for correction
– E.g : 6 + 8 = 14

A = 0110 6
B = 1000 8
S = 1110 14 Invalid BCD
Add 6 for correction
S = 1110
6 = 0110
Ans = 10100
0001 0100
1 4
BCD Addition
• Case 3 : Sum equals to 9 or less with carry 1
– Add 6 bits for correction
– E.g : 8 + 9 = 17

A = 1000 8
B = 1001 9
S= 10001
0001 0001 11 Invalid Result
Add 6 for correction
S = 0001 0001
6 = 0110
Ans = 0001 0111
1 7 Correct Result
Self Task
• Add 24 + 18 = 42

A = 0010 0100 24
B = 0001 1000 18
S = 0011 1100 312 Invalid
Add 6 = 0110
= 0100 0010
4 2 Correct Result
Gray Code 0000 0
0001 1
0011 2
• Use to detect errors in 0010 3
the bits 0110
0111
4
5
• Two numbers differ only 0101 6
0100 7
in 1 bit position 1100 8
• 0-15 decimal 1101 9
1111 10
1110 11
1010 12
1011 13
1001 14
1000 15
Conversions
• Gray code to binary code (Discard Carries)
G =1 1 1 0

B =1 0 1 1
Conversions
• Binary code to Gray code (Add)

• B = 1 0 1 1 (Discard Carries)

• G = 1 1 1 0
Self Task

• Convert the following binary in gray


– 1100,11010
• Convert the following gray in binary
– 1010,1000
Error Detection Codes
• Parity Method for Error Detection
– A parity bit is attached to a group of bits to make
the total number of 1’s in a group always even or
odd.
Error Detection Codes
• Detecting an error
– Suppose we have transmitted BCD 6 using parity
bit.

– We received the data with some errors.


Self Task
• Assign the proper even parity bit to the
following codes.
– 1010, 111000, 101101, 1000111001001
Self Task
• An odd parity system receives the following
code groups:
– 10110, 11010, 110011, 110101110100,
1100010101010
– Determine which groups, if any, are in error.

You might also like