Complement Theory 1’s and, 2’s complement operation

Slides:



Advertisements
Similar presentations
Conversion and Coding (12)10.
Advertisements

Lab 10 : Arithmetic Systems : Adder System Layout: Slide #2 Slide #3 Slide #4 Slide #5 Arithmetic Overflow: 2’s Complement Conversions: 8 Bit Adder/Subtractor.
Company LOGO Edit your slogan here DKT 122/3 DIGITAL SYSTEM 1 WEEK #3 NUMBER SYSTEMS, OPERATION & CODES (PART 2)
Forging new generations of engineers. Binary Addition & Subtraction.
Chapter 1 Binary Systems 1-1. Digital Systems
VIT UNIVERSITY1 ECE 103 DIGITAL LOGIC DESIGN CHAPTER I NUMBER SYSTEMS AND CODES Reference: M. Morris Mano & Michael D. Ciletti, "Digital Design", Fourth.
1.6 Signed Binary Numbers.
Digital Systems and Logic Design
Binary Arithmetic & Data representation
CHAPTER 1 INTRODUCTION NUMBER SYSTEMS AND CONVERSION.
CHAPTER 1 INTRODUCTION NUMBER SYSTEMS AND CONVERSION
1 EENG 2710 Chapter 1 Number Systems and Codes. 2 Chapter 1 Homework 1.1c, 1.2c, 1.3c, 1.4e, 1.5e, 1.6c, 1.7e, 1.8a, 1.9a, 1.10b, 1.13a, 1.19.
ECE 301 – Digital Electronics Unsigned and Signed Numbers, Binary Arithmetic of Signed Numbers, and Binary Codes (Lecture #2)
Summer 2012ETE Digital Electronics1 Binary Arithmetic of Signed Binary Numbers.
1 Lecture 3 ENGRE 254 1/14/09. 2 Lecture 1 review Digital signals assume two values represented by “0” and “1”. Typically a “0” represents a voltage near.
Number Systems Binary to Decimal Octal to Decimal Hexadecimal to Decimal Binary to Octal Binary to Hexadecimal Two’s Complement.
ECE 331 – Digital System Design Representation and Binary Arithmetic of Negative Numbers and Binary Codes (Lecture #10) The slides included herein were.
Tutorial: ITI1100 Dewan Tanvir Ahmed SITE, UofO
Digital Logic Lecture 3 Binary Arithmetic By Zyad Dwekat The Hashemite University Computer Engineering Department.
Digital Fundamentals Tenth Edition Floyd Chapter 2 © 2008 Pearson Education.
2's Complement Arithmetic
Introduction to Digital Electronics Lecture 2: Number Systems.
Number Systems. The position of each digit in a weighted number system is assigned a weight based on the base or radix of the system. The radix of decimal.
N 3-1 Data Types  Binary information is stored in memory or processor registers  Registers contain either data or control information l Data are numbers.
Number Systems Decimal (Base 10) –10 digits (0,1,2,3,4,5,6,7,8,9) Binary (Base 2) –2 digits (0,1) Digits are often called bits (binary digits) Hexadecimal.
Lecture 4: Digital Systems & Binary Numbers (4)
DIGITAL Logic DESIGN Digital system and binary numbers Lecturer: Ms. Farwah Ahmad.
CS2100 Computer Organisation
Unit 1 Introduction Number Systems and Conversion.
Chapter 1 Digital Systems and Binary Numbers
Digital Logic & Design Adil Waheed Lecture 02.
CHAPTER 1 INTRODUCTION NUMBER SYSTEMS AND CONVERSION
CS2100 Computer Organisation
Negative numbers: Week 10 Lesson 1
2's Complement Arithmetic
CHAPTER 1 INTRODUCTION NUMBER SYSTEMS AND CONVERSION
CHAPTER 1 : INTRODUCTION
Number systems and codes
Introduction to Chapter 2
Binary Arithmetic Binary arithmetic is essential in all digital computers and in many other types of digital systems. Addition, Subtraction, Multiplication,
Logistics Always read the Calendar at
Digital Systems and Binary Numbers
Introduction The term digital is derived from the way computers perform operation, by counting digits. Application of digital technology: television, communication.
Lecture 2 Topics Binary Arithmetic (Unsigned binary operands)
Digital Electronics Number Systems and Codes
Number Systems.
XOR, XNOR, and Binary Adders
Binary Addition & Subtraction
2 Number Systems and Codes Edited by Jerry Bernardini.
Lecture 2 Topics Binary Arithmetic (Unsigned binary operands)
INTRODUCTION TO LOGIC DESIGN Chapter 1 Digital Systems and Binary Numbers gürtaçyemişçioğlu.
Complement Theory 1’s and, 2’s complement operation
MMNSS COLLEGE,KOTTIYAM DEPARTMENT OF PHYSICS
Digital Electronics & Logic Design
Digital Logic & Design Lecture 03.
XOR, XNOR, & Binary Adders
2’s Complement Arithmetic
Digital Logic Design (ECEg3141) 2. Number systems, operations & codes 1.
C1 Number systems.
2’s Complement form 1’s complement form 2’s complement form
XOR, XNOR, and Binary Adders
Binary to Decimal Conversion
ECE 171 Digital Circuits Chapter 2 Binary Arithmetic
ECE 331 – Digital System Design
Number Systems.
XOR, XNOR, and Binary Adders
Arithmetic Circuits.
2's Complement Arithmetic
Chapter 1 (Part c) Digital Systems and Binary Numbers
Presentation transcript:

Complement Theory 1’s and, 2’s complement operation (r-1)’s and r’s complement 9’s and, 10’s complement operation Binary Codes (BCD Arithematic) Weighted Codes Error Processing Codes Alphanumeric codes.

Example 1 Get 1’s complement of 50 Complement Theory Example 1 Get 1’s complement of 50 50 = 00000101 Complement Digits  11111010

1’s Complement Arithmetic (ADD/SUB Method) Read both the operands Negative operand(s) (if any) is converted into 1’s complement form Add both the numbers If carry is generated (i.e. =1) then the resultant number is positive. Add ONE to the output of setp4, to get the final answer. If carry is not generated then the answer is Negative and available in 1’s complement form. Convert output of step 6 into 1’s complement to get final answer.

1’s Complement Theory Example 1 : Subtract 1010 from 1111 using 1’s complement theory. (15-10 Small negative) 1 1 1 1 + 0 1 0 1 1’s complement 1 0 1 0 0 1 0 1 1] 0 1 0 0 + 0 0 0 1 0 1 0 1 =(5) Carry “1” means the answer is positive . 

1’s Complement Theory Example 2 : Subtract 1010 from 1000 using 1’s complement theory. (Large negative 8-10) 1 0 0 0 + 0 1 0 1 1’s complement 1 0 1 0 0 1 0 1 0] 1 1 0 1 Carry “0” means the answer is negative and available in 1’s complement form. 1 1 0 1 0 0 1 0 = (2)

2’s Complement Arithmetic How to get 2’s complement form Arithmetic operation using 2’s complement theory

2’s Complement Arithmetic (How to get 2’s complement form..?) Example 1 5 = 00000101 Complement Digits  11111010 Add 1 +1 -5 = 11111011 Example 2 -13 = 11110011 Complement Digits  00001100 Add 1 +1 13 = 00001101

2’s Complement Arithmetic (Method) Read both the operands Negative operand (if any) is converted into 2’s complement form Add both the numbers (2’s complement of negative operand with the other one). If carry is generated (i.e. =1) then the resultant number is positive and in original form If carry is not generated(when we have negative operand) then the carry is assumed =0. Carry zero means the resultant number is negative and in a 2’s complement form. Convert the 2’s complement form into the original form.

2's Complement Arithmetic Digital Electronics  Lesson 2.4 – Specific Comb Circuit & Misc Topics POS + NEG → POS Answer Take the 2’s complement of the negative number and use regular binary 8-bit addition. 9 + (-5) 4  00001001 + 11111011  100000100 Last Bit = 1: Answer is Positive Disregard 9th Bit This example shows the addition of one positive and one negative numbers. Note that this is done in the same way as subtracting a positive number from a positive number. In this case, the answer is positive. 00000101  11111010 +1 11111011 2’s Complement Process Project Lead The Way, Inc. Copyright 2009

2's Complement Arithmetic Digital Electronics  Lesson 2.4 – Specific Comb Circuit & Misc Topics POS + NEG → NEG Answer Take the 2’s complement of the negative number and use regular 8-bit binary addition. (-9) + 5 -4 11110111  + 00000101  011111100 Last Bit = 0: Answer is Negative . Discard the last bit This slide demonstrates the addition of one positive and one negative number. Again, this is is the same a subtracting a positive number from a positive number. In this case the answer happens to be negative. 11111100  00000011 +1 00000100 To Check: Perform 2’s Complement On Answer 00001001  11110110 +1 11110111 2’s Complement Process Project Lead The Way, Inc. Copyright 2009

Verify the logic using following combinations: 1: (10) –(01) 2: (10) –(02) 3: (10) –(05) 4: (10) –(08) 5: (10) –(09) 6: (10) –(10) 7: (210) –(08) 8: (120) –(55) 9: (52) –(18)

2’s Complement Arithmetic (Examples) A+B A B 2’s of B Addition Ans A=10 B=-1 1 0 1 0 0 0 0 1 1 1 1 0 1 1 1 1 1 1 1 1 CY =1 So ans is +ve 1 1 0 0 1 +9 B=-2 0 0 1 0 1 1 0 1 1 1 1 0 CY =1 So ans is +ve 1 1 0 0 0 +8 B=-5 0 1 0 1 1 0 1 1 1 0 1 0 1 CY =1 So ans is +ve +5 B=-8 1 0 0 0 0 1 1 1 1 0 0 1 0 CY =1 So ans is +ve +2 B=-9 1 0 0 1 0 1 1 0 1 0 0 0 1 CY =1 So ans is +ve +1 B=-10 1 0 0 0 0 CY =1 So ans is +ve +0

Example: Perform 2’s complement subtraction on 210-08 201= 1 1 0 1 0 0 1 0 8= 0 0 0 0 1 0 0 0 2’s complement of 8 is = 1 1 1 1 1 0 0 0 Add both the numbers: 1 1 0 1 0 0 1 0 +1 1 1 1 1 0 0 0 1 1 1 0 0 1 0 1 0 Carry = 1 means and is positive +202

2’s Complement Arithmetic (Examples on varying number of bits) Example: Perform 2’s complement arithmetic for (30)-(50) using 1: 6-bit number system 2: 8-bit number system

Example: Perform 2’s complement arithmetic for (30)-(50) using: 1: 6-bit number system 2: 8-bit number system (30)= 0 0 0 1 1 1 1 0 (-50)= 0 0 1 1 0 0 1 0 2’s complement 1 1 0 0 1 1 0 1 0 0 0 0 0 0 0 1 1 1 0 0 1 1 1 0 (30)= 0 1 1 1 1 0 (-50)= 1 1 0 0 1 0 2’s complement 0 0 1 1 0 1 0 0 0 0 0 1 0 0 1 1 1 0 Add both the numbers Add both the numbers 0 0 0 1 1 1 1 0 1 1 0 0 1 1 1 0 0 1 1 1 1 0 0 1 1 1 0 1 1 0 0 0 0 1 1 1 0 0 1 0 1 1 0 0 Carry =0 means number is negative and in 2’s compl form 0 0 0 1 0 0 1 1 0 0 0 0 0 0 0 1 0 0 0 1 0 1 0 0 = -20 Carry =0 means number is negative and in 2’s compl form 0 1 0 0 1 1 0 0 0 0 0 1 0 1 0 1 0 0 = -20

(r-1)’s and r’s complement Example of decimal number system So r becomes 10’s complement And (r-1) becomes 9’s complement

How to get (r-1)’s complement of decimal number…? How do we get (r-1)’s complement …? (r-1)′s i.e. 9’s complement of decimal number can be obtained by ((10n - 1)-number) where n represents the number of digits in given number. Example 1: Find 9’s complement of   (1234)10 9′s complement = (104-1)-1234 = 9999-1234 = 8765 How do we get (r)’s complement …? r's i.e. 10’s complement can be obtained by (10n – number) where n represents the number of digits in given number. Example 2: Find 10′s complement = 104-1234 = 8766. We will move to subtraction using them. Remember always the number to be subtracted (negative number) is converted to 9′s or 10′s complement.

9’s Complement Arithmetic Example 1: Get 9’s complement of following numbers (19)10 , (146)10, (4397)10 99 999 9999 -19 -146 -4397 80 853 5602

9’s Complement Arithmetic Example 1: Perform subtraction using 9’s complement on the data set given below. a: 18-06, b: 39-23 c: 34-49 d: 49-84 We will ADD 93 and 18 9 3 + 1 8 1 1 1 A carry is generated means answer is +ve ADD the carry back to the sum “11”. 1 1 + 1 1 2 06 is negative number, We will get 9’s complement of 06 9 9 - 0 6 9 3 Try for (018) – (006)

9’s Complement Arithmetic Example 2: Perform 9’s complement subtraction on the data set given below. a: 18-06, b: 39-23 c: 34-49 d: 49-84 We will ADD 76 and 39 7 6 + 3 9 1 1 5 A carry is generated . ADD the carry back to the sum “15”. 1 5 + 1 1 6 23 is negative number, We will get 9’s complement of 23 9 9 - 2 3 7 6 Try for 039-023

9’s Complement Arithmetic Example 3: Perform 9’s complement subtraction on the data set given below. a: 18-06, b: 39-23 c: 34-49 d: 49-84 We will ADD 50 and 34 5 0 + 3 4 0 8 4 A carry is not generated that means answer is Negative. Get 9’s complement of 84 9 9 _ 8 4 1 5 Answer is -15 49 is negative number, We will get 9’s complement of 49 9 9 - 4 9 5 0 Try for 034-049

9’s Complement Arithmetic Example 4: Perform 9’s complement subtraction on the data set given below. a: 18-06, b: 39-23 c: 34-49 d: 49-84 We will ADD 15 and 49 4 9 + 1 5 0 6 4 A carry is not generated that means answer is Negative. Get 9’s complement of 64 9 9 _ 6 4 3 5 Answer is -35 84 is negative number, We will get 9’s complement of 84 9 9 - 8 4 1 5 Try for 049-084

10’s Complement Arithmetic Example 1: Perform 10’s complement subtraction on the data set given below. a: 24-09, b: 69-32 c: 265-347 We will ADD 91 and 24 2 4 + 9 1 1 1 5 09 is negative number, We will get 10’s complement of 09 9 9 - 0 9 9 0 + 0 1 9 1 A carry is generated that means answer is Positive. Answer is +15 Try for 024-009

10’s Complement Arithmetic Example 2: Perform 10’s complement subtraction on the data set given below. a: 24-09, b: 69-32 c: 265-347 We will ADD 68 and 69 6 8 + 6 9 1 3 7 32 is negative number, We will get 10’s complement of 32 9 9 - 3 2 6 7 + 0 1 6 8 A carry is generated that means answer is Positive. Answer is +37 Try for 069-032

10’s Complement Arithmetic Example 3: Perform 10’s complement subtraction on the data set given below. a: 24-09, b: 69-32 c: 265-347 We will ADD 653 and 265 653 + 265 0 918 347 is negative number, We will get 10’s complement of 347 9 9 9 - 3 4 7 6 5 2 + 0 1 6 5 3 A carry is not generated that means answer is Negative and in 10’s complement form. Get 10’s complement form of 918 9 9 9 -9 1 8 0 8 1 +0 0 1 0 8 2 Ans = -82 Try for 0265-0347

BCD Arithmetic

Binary Codes Weighted Codes (8421, 5421) Non Weighted codes (Excess-3 , BCD, Gray/Reflected codes) Error Processing Codes (PARITY Bits, Hamming Codes) Alphanumeric Codes (ASCII, EBCDIC)

1: Weighted Codes: Weighted binary codes are those binary codes which obey the positional weight principle. Each position of the number represents a specific weight. 5 4 2 1 8 4 2 1 0 0 0 0 0 1 0 1 5 0 1 0 0 4 0 0 1 0 2 0 0 0 1 1 0 1 1 1 7 1 1 1 1 12 15

2: Non-Weighted Codes: 2.1: Excess-3 is a non-weighted coding method. With excess-3, we add 3 to a decimal number before converting it to binary. Example: (0001)2 = (0100)Excess-3 (0010)2 = (0101)Excess-3 2.2: BCD (Binary Coded Decimals) is a non-weighted coding method. Individual decimal digits are converted into equivalent binary bits. Example: (321)2 = (0011 0010 0000)BCD (000)2 = (0000 0000 0000)BCD (80)2 = (1000 0000)BCD (00)2 = (0000 0000)BCD

2: Non-Weighted Codes: 2.3: Gray Codes: It is also called as Reflected Binary codes. It is generated via getting mirror image of given data. Example : 4 bit Gray codes. 1 1 1 1 1 1 0 1 1 0 1 0 0 1 0 0 1 0 1 1 1 1 1 1 0 0 1 0 0 1 1 0 0 1 0 0 0

2: Code Conversion: Converting Binary Codes to Gray codes Method: Copy MSB of Binary code to MSB of Gray code. Add MSB of Binary with Next MSB of Binary to get next Gray code. Discard the carry Repeat the same process till we get the LSB Example: Convert (0001)2 into Gray code. 0 0 0 1 0+0= 0 0+0= 0 0+1= 1 1

2: Code Conversion: Converting Binary Codes to Gray codes Method: Copy MSB of Binary code to MSB of Gray code. Add MSB of Binary with Next MSB of Binary to get next Gray code. Discard the carry Repeat the same process till we get the LSB Example: Convert (1011)2 into Gray code. 1 0 1 1 1+0= 1 0+1= 1 1+1= 0 1 1 1

2: Code Conversion: Converting Gray Codes to Binary codes Method: Copy MSB of Gray code to MSB of Binary code. If next bit of Gray code is “1”, then invert the present binary bit as next bit. If next bit of Gray code is “0” then copy the present binary bit as next bit. Example: Convert (1011) gray into Binary code. 1 0 1 1 1 1 1

BCD Arithmetic: Example 1: (83) +(11) =(94) 1 0 0 0 0 0 1 1 1 0 0 0 0 0 1 1 11 1 0 0 1 1 0 0 1 Example 2: (83) +(18) =(101) 1 0 0 0 0 0 1 1 11 0 0 0 1 1 0 0 0 1 0 0 1 0 1 0 0 = (94) 1 0 1 0 1 1 0 1 1 0 1 1 0 1 0 0 0 0 1