MC1601 Computer Organization

Similar documents
Computer Sc. & IT. Digital Logic. Computer Sciencee & Information Technology. 20 Rank under AIR 100. Postal Correspondence

CHAPTER TWO. Data Representation ( M.MORRIS MANO COMPUTER SYSTEM ARCHITECTURE THIRD EDITION ) IN THIS CHAPTER

Digital Systems and Binary Numbers

Korea University of Technology and Education

Chapter 1 Review of Number Systems

BINARY SYSTEM. Binary system is used in digital systems because it is:

CHAPTER V NUMBER SYSTEMS AND ARITHMETIC

DATA REPRESENTATION. Data Types. Complements. Fixed Point Representations. Floating Point Representations. Other Binary Codes. Error Detection Codes

Number System. Introduction. Decimal Numbers

Digital Fundamentals. CHAPTER 2 Number Systems, Operations, and Codes

Positional notation Ch Conversions between Decimal and Binary. /continued. Binary to Decimal

Chapter 1. Digital Systems and Binary Numbers

Moodle WILLINGDON COLLEGE SANGLI. ELECTRONICS (B. Sc.-I) Introduction to Number System

CS 121 Digital Logic Design. Chapter 1. Teacher Assistant. Hadeel Al-Ateeq

Lecture (01) Digital Systems and Binary Numbers By: Dr. Ahmed ElShafee

Digital Systems and Binary Numbers

Basic Definition INTEGER DATA. Unsigned Binary and Binary-Coded Decimal. BCD: Binary-Coded Decimal

Chapter 3: part 3 Binary Subtraction

Numbering systems. Dr Abu Arqoub

Lecture (02) Operations on numbering systems

D I G I T A L C I R C U I T S E E

Number representations

Electronics Engineering ECE / E & T

Number Systems Base r

Digital Systems and Binary Numbers

in this web service Cambridge University Press

Semester Transition Point. EE 109 Unit 11 Binary Arithmetic. Binary Arithmetic ARITHMETIC

Logic Circuits I ECE 1411 Thursday 4:45pm-7:20pm. Nathan Pihlstrom.

COMP Overview of Tutorial #2

CHW 261: Logic Design

Binary Addition. Add the binary numbers and and show the equivalent decimal addition.

Numeral Systems. -Numeral System -Positional systems -Decimal -Binary -Octal. Subjects:

Lecture (01) Introduction Number Systems and Conversion (1)

MYcsvtu Notes DATA REPRESENTATION. Data Types. Complements. Fixed Point Representations. Floating Point Representations. Other Binary Codes

Digital Fundamentals

Binary Systems and Codes

MACHINE LEVEL REPRESENTATION OF DATA

Number Systems and Binary Arithmetic. Quantitative Analysis II Professor Bob Orr

Number Systems CHAPTER Positional Number Systems

Data Representation COE 301. Computer Organization Prof. Muhamed Mudawar

World Inside a Computer is Binary

Binary Addition & Subtraction. Unsigned and Sign & Magnitude numbers

Number Systems. Both numbers are positive

1010 2?= ?= CS 64 Lecture 2 Data Representation. Decimal Numbers: Base 10. Reading: FLD Digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9

Chapter 2. Positional number systems. 2.1 Signed number representations Signed magnitude

Numerical Representations On The Computer: Negative And Rational Numbers

CS & IT Conversions. Magnitude 10,000 1,

UNIT - I: COMPUTER ARITHMETIC, REGISTER TRANSFER LANGUAGE & MICROOPERATIONS

DLD VIDYA SAGAR P. potharajuvidyasagar.wordpress.com. Vignana Bharathi Institute of Technology UNIT 1 DLD P VIDYA SAGAR

Chapter 10 Binary Arithmetics

Numerical Representations On The Computer: Negative And Rational Numbers

COE 202: Digital Logic Design Number Systems Part 2. Dr. Ahmad Almulhem ahmadsm AT kfupm Phone: Office:

A complement number system is used to represent positive and negative integers. A complement number system is based on a fixed length representation

Digital Logic Lecture 2 Number Systems

Chapter 2: Number Systems

DIGITAL SYSTEM FUNDAMENTALS (ECE 421) DIGITAL ELECTRONICS FUNDAMENTAL (ECE 422) COURSE / CODE NUMBER SYSTEM

COMPUTER ARITHMETIC (Part 1)

1. NUMBER SYSTEMS USED IN COMPUTING: THE BINARY NUMBER SYSTEM

Computer Organization

Chapter 4 Arithmetic Functions

Number Systems Prof. Indranil Sen Gupta Dept. of Computer Science & Engg. Indian Institute of Technology Kharagpur Number Representation

Number Systems and Conversions UNIT 1 NUMBER SYSTEMS & CONVERSIONS. Number Systems (2/2) Number Systems (1/2) Iris Hui-Ru Jiang Spring 2010

ECE/Comp Sci 352 Digital Systems Fundamentals. Charles R. Kime Section 2 Fall Logic and Computer Design Fundamentals

Number Systems Standard positional representation of numbers: An unsigned number with whole and fraction portions is represented as:

UNIT 2 NUMBER SYSTEM AND PROGRAMMING LANGUAGES

CHAPTER 2 Number Systems

Bachelor of Computer Application DIGITAL TECHNIQUES. Block-1

UNIT 7A Data Representation: Numbers and Text. Digital Data

10.1. Unit 10. Signed Representation Systems Binary Arithmetic

Level ISA3: Information Representation

CO212 Lecture 10: Arithmetic & Logical Unit

Goals for this Week. CSC 2400: Computer Systems. Bits, Bytes and Data Types. Binary number system. Finite representations of binary integers

2.1. Unit 2. Integer Operations (Arithmetic, Overflow, Bitwise Logic, Shifting)

2 Number Systems 2.1. Foundations of Computer Science Cengage Learning

Decimal & Binary Representation Systems. Decimal & Binary Representation Systems

Rui Wang, Assistant professor Dept. of Information and Communication Tongji University.

DIGITAL SYSTEM DESIGN

COE 202- Digital Logic. Number Systems II. Dr. Abdulaziz Y. Barnawi COE Department KFUPM. January 23, Abdulaziz Barnawi. COE 202 Logic Design

DIGITAL ARITHMETIC: OPERATIONS AND CIRCUITS

unused unused unused unused unused unused

COMPUTER ARCHITECTURE AND ORGANIZATION. Operation Add Magnitudes Subtract Magnitudes (+A) + ( B) + (A B) (B A) + (A B)

Chapter 3 Data Representation

CPE 323 REVIEW DATA TYPES AND NUMBER REPRESENTATIONS IN MODERN COMPUTERS

TOPIC: NUMBER SYSTEMS

Arithmetic Processing

Chapter 5: Computer Arithmetic. In this chapter you will learn about:

CMPE223/CMSE222 Digital Logic Design. Positional representation

Learning Objectives. Binary over Decimal. In this chapter you will learn about:

Chapter 5: Computer Arithmetic

EE 109 Unit 6 Binary Arithmetic

THE LOGIC OF COMPOUND STATEMENTS

Advanced Computer Architecture-CS501

Chapter 10 - Computer Arithmetic

CPE 323 REVIEW DATA TYPES AND NUMBER REPRESENTATIONS IN MODERN COMPUTERS

LESSON TITLE. Language English Local Language Introduction to Computer Science. Mr. VAR Sovannrath Submission Date October 30th, 2014 Version 1.

(+A) + ( B) + (A B) (B A) + (A B) ( A) + (+ B) (A B) + (B A) + (A B) (+ A) (+ B) + (A - B) (B A) + (A B) ( A) ( B) (A B) + (B A) + (A B)

Chapter 2. Data Representation in Computer Systems

Lecture 2: Number Systems

Ms Sandhya Rani Dash UNIT 2: NUMBER SYSTEM AND CODES. 1.1 Introduction

l l l l l l l Base 2; each digit is 0 or 1 l Each bit in place i has value 2 i l Binary representation is used in computers

Transcription:

MC1601 Computer Organization Unit 1 : Digital Fundamentals Lesson1 : Number Systems and Conversions (KSB) (MCA) (2009-12/ODD) (2009-10/1 A&B)

Coverage - Lesson1 Shows how various data types found in digital computers are represented in binary form in computer registers Representation of numbers employed in arithmetic operations and binary coding of symbols in data processing, are emphasized KSB-1601-07 2

Lesson1 Number Systems and Conversions 1.Data Types 2.Complements 3.Fixed Point Representation KSB-1601-07 3

1.Data Types Binary information is stored in digital computers in memory or processor registers Registers are made up of Flip-Flops which are two state memory devices that can store either 1 s or 0 s Binary number system is the most natural number system for digital computers like decimal number system for humans The binary information in computers can be either Data or Instructions KSB-1601-07 4

Information stored in computers Instructions Data Non-Numerical Data Numerical data Letters Special Control Floating Fixed symbols chars point point Binary Octal Hexadecimal Binary Octal Hex. KSB-1601-07 5

NUMERIC DATA REPRESENTATION Two types of Number Systems 1.Nonpositional number system Roman number system 2.Positional number system Each digit position has a value called a weight associated with it Examples: Decimal, Octal, Hexadecimal, Binary Base (or radix) R of a number system uses R distinct symbols Numbers are represented by a string of digit symbols Example A R = a n-1 a n-2... a 1 a 0.a -1 a -m Value V(A R ) = n 1 i= m i a i R R = 10 Decimal number system, R = 8 Octal, Radix point(.) separates the integer portion and the fractional portion R = 2 Binary R = 16 Hexadecimal KSB-1601-07 6

WHY POSITIONAL NUMBER SYSTEM IN DIGITAL COMPUTERS? Major Consideration is the COST and TIME - Cost of building hardware Arithmetic and Logic Unit, CPU, Communications - Time to processing Arithmetic - Addition of Numbers - Table for Addition * Non-positional Number System - Table for addition is infinite --> Impossible to build, very expensive even if it can be built * Positional Number System - Table for Addition is finite --> Physically realizable, but cost wise the smaller the table size, the less expensive --> Binary is favorable to Decimal Binary Addition Table 0 1 0 0 1 1 1 10 Decimal Addition Table 0 1 2 3 4 5 6 7 8 9 0 0 1 2 3 4 5 6 7 8 9 1 1 2 3 4 5 6 7 8 9 10 2 2 3 4 5 6 7 8 9 1011 3 3 4 5 6 7 8 9 101112 4 4 5 6 7 8 9 10111213 5 5 6 7 8 9 1011121314 6 6 7 8 9 101112131415 7 7 8 9 10111213141516 8 8 9 1011121314151617 9 9 101112131415161718 KSB-1601-07 7

REPRESENTATION OF NUMBERS - POSITIONAL NUMBERS Decimal Binary Octal Hexadecimal 00 0000 00 0 01 0001 01 1 02 0010 02 2 03 0011 03 3 04 0100 04 4 05 0101 05 5 06 0110 06 6 07 0111 07 7 08 1000 10 8 09 1001 11 9 10 1010 12 A 11 1011 13 B 12 1100 14 C 13 1101 15 D 14 1110 16 E 15 1111 17 F Binary, octal, and hexadecimal conversion 1 2 7 5 4 3 1 0 1 0 1 1 1 1 0 1 1 0 0 0 1 1 A F 6 3 Octal Binary Hexa KSB-1601-07 8

Conversion of Bases-Decimal to Base R Step1: Separate the number into its Integer and Fraction part Step2: Convert Integer part in to base R as given below Divide the integer part by R giving an integer quotient and reminder The quotient is again is divided by R to give a new quotient and reminder Repeat the process until integer quotient becomes 0 The coefficients of the converted number are obtained from the reminders, with the 1 st reminder giving the low order bit of the converted number KSB-1601-07 9

Conversion of Bases-Decimal to Base R (contd..) Step3: Covert the Fraction part into base R as given below Multiply the fractional part by R to give an integer and a fraction New fraction (without integer) is multiplied again by R to give a new integer and a new fraction This process is repeated until the fraction part becomes zero or until the number of digits obtained gives desired accuracy The coefficients of the fraction are obtained from the integer digits with the 1 st integer computed being the digit to be placed next to the radix point Step4:Combine the two parts to give the total required conversion KSB-1601-07 10

Conversion of Bases-Base R to Decimal Base R to Decimal Conversion A = a n-1 a n-2 a n-3 a 0. a -1 a -m V(A) = Σ a k R k (736.4) 8 = 7 x 8 2 + 3 x 8 1 + 6 x 8 0 + 4 x 8-1 = 7 x 64 + 3 x 8 + 6 x 1 + 4/8 = (478.5) 10 (110110) 2 =... = (54) 10 (110.111) 2 =... = (6.785) 10 (F3) 16 =... = (243) 10 ( B65F) 16 = =(46687) 10 KSB-1601-07 11

Exercise 1 1.Convert decimal 41 to binary 2.Convert decimal 153 to octal 3.Convert decimal 0.6875 to binary 4.Convert decimal 0.513 to octal 5.Convert decimal 1938 to hexadecimal KSB-1601-07 12

Exercise 1 - Answers 1.Convert decimal 41 to binary Ans: 101001 2 2.Convert decimal 153 to octal Ans: 231 8 3.Convert decimal 0.6875 to binary Ans: 0.1011 2 4.Convert decimal 0.513 to octal Ans: 0.406517.. 8 5.Convert decimal 1938 to hexadecimal Ans: 792 16 KSB-1601-07 13

Exercise 2 1.Convert the following numbers with the indicated bases to decimal: (12121) 3 ; (4310) 5 ; (50)7 ; (198) 12 2.Convert the following decimal numbers to binary 1231 ; 673 ; 1998 3.Convert the following decimal numbers to bases indicated : 7562 to octal ; 1938 to Hexadecimal ; 175 to binary KSB-1601-07 14

Exercise 2 - Answers 1.Convert the following numbers with the indicated bases to decimal: (12121) 3 ; (4310) 5 ; (50)7 ; (198) 12 Ans: 121 ; 581 ; 35 ; 260 2.Convert the following decimal numbers to binary 1231 ; 673 ; 1998 Ans: 10011001111;1010100011;11111001110 3.Convert the following decimal numbers to bases indicated : 7562 to octal ; 1938 to Hexadecimal ; 175 to binary Ans: 166128 8 ; 792 16 ; 10101111 2 KSB-1601-07 15

Octal and Hexadecimal numbers Since 2 3 = 8 and 2 4 = 16 Each octal digit corresponds to 3 binary digits Each hexadecimal digit corresponds to 4 binary digits Conversion from binary to octal is accomplished - By partitioning the binary number in to groups of 3 digits each, starting from the binary point and proceeding to the left (for the integer portion) and then to the right (for the fraction portion) Assign the corresponding octal digit to each group Conversion from binary to hexadecimal is similar, except that the binary number is divided in to groups of 4 digits KSB-1601-07 16

Example Binary to octal: 10 110 001 101 011. 111 100 000 110 2 6 1 5 3. 7 4 0 6 Binary Hexadecimal: 10 1100 0110 1011. 1111 0010 2 C 6 B. F 2 KSB-1601-07 17

Octal and Hexadecimal numbers (contd..) Conversion from octal or hexadecimal to binary is done by a procedure reverse to the above Each octal digit is converted to its 3 digit binary equivalent Similarly each hexadecimal digit is converted to its 4 digit binary equivalent Examples (673.124) 8 = (110 111 011. 001 010 100) 2 (306.D) 16 = (0011 0000 0110. 1101) 2 KSB-1601-07 18

Octal Number Binary Number Hexadecimal Number R-Based Number Decimal Number KSB-1601-07 19

Exercise 3 1.Convert the hexadecimal number F3A7C2 to Binary and Octal 2.Convert the Octal number 776553 to Binary and hexadecimal KSB-1601-07 20

Exercise 3 - Answers 1.Convert the hexadecimal number F3A7C2 to Binary and Octal Ans: 1111 0011 1010 0111 1100 0010 2 74723702 8 2.Convert the Octal number 776553 to Binary and hexadecimal Ans: 111 111 110 101 101 011 2 3FD6B1 6 KSB-1601-07 21

2. Complements Complements are used in digital computers for simplifying the subtraction operation and for logical manipulation There are two types of complements for each base R system: R s complement (R-1) s complement In binary it is 2 s and 1 s complement In decimal it is 10 s and 9 s complement (Substitute R = 2 for binary, R = 10 for decimal) KSB-1601-07 22

(R-1) s Complement Given a number N in base R having n digits, the (R-1) s complement of N is defined as (R n -1) N For decimal numbers R = 10 and (R-1) = 9 and (R-1) complement is called 9 s complement The 9 s complement of any decimal number is obtained by subtracting each digit from 9 For binary numbers R = 2 and (R-1) = 1 and (R-1) complement is called 1 s complement The 1 s complement of a binary number is obtained by subtracting each digit from 1(which means to change 1 s to 0 s and 0 s to 1 s) KSB-1601-07 23

Example 1.Find the 9 s complement of 12389 Method1: Given N=12389, R=10, n=5 9 s complement of 12389 is = (10 5-1) 12389 = 87610 Method2: 99999-12389 = 87610 2.Find the 1 s complement of 1011001 Method1: Given N=1011001, R=2, n=7 1 s complement of 1011001 = (2 7-1) 1011001 = (128-1) 1011001 = (127) 1011001 = 1111111-1011001 = 0100110 Method2: Change 1 s to 0 s and 0 s to 1 s =0100110 KSB-1601-07 24

R s Complement The R s complement of an n-digit number N in base R is defined as R n N for N 0 and 0 for N=0 For decimal numbers R=10 and is called 10 s complement The 10 s complement of any decimal number is obtained by first taking 9 s complement and adding 1 to this The 2 s complement of any binary number is obtained by first taking 1 s complement and adding 1 to this KSB-1601-07 25

Complements with radix points If the original number N contains a radix point it should be removed temporarily to form R s or (R-1) s complement The radix point is then restored to the complemented number in the same relative position Note that the complement of complement restores the number to its original value KSB-1601-07 26

Exercise 4 1.Obtain the 9 s complement of the following eight-digit decimal numbers: 12349876 ; 00980100; 90009951; 00000000 2.Obtain the 10 s complement of the following six-digit decimal numbers: 123900; 090657; 100000; 000000 3.Obtain the 1 s and 2 s complements of the following eight-digit binary numbers: 10101110; 10000001; 00000001; 00000000 KSB-1601-07 27

Exercise 4 - Answers 1.Obtain the 9 s complement of the following eight-digit decimal numbers: 12349876 ; 00980100; 90009951; 00000000 Ans: 9 s complements of 12349876 is 87650123 00980100 is 99019899 90009951 is 09990048 00000000 is 99999999 KSB-1601-07 28

Exercise 4 - Answers 2.Obtain the 10 s complement of the following six-digit decimal numbers: 123900; 090657; 100000; 000000 Ans: 10 s complements of 123900 is 876100 090657 is 909343 100000 is 900000 000000 is 000000 KSB-1601-07 29

Exercise 4 - Answers 3.Obtain the 1 s and 2 s complements of the following eight-digit binary numbers: 10101110; 10000001; 00000001; 00000000 Ans: 1 s complement 2 s complement 0101 0001 0101 0010 0111 1110 0111 1111 1111 1110 1111 1111 1111 1111 0000 0000 KSB-1601-07 30

Use of Complements in the subtraction of Unsigned numbers Subtraction of two n-digit unsigned numbers M N (N 0) in base R can be obtained as follows: 1.Add the minuend M to the R s complement of the subtrahend N ( this performs M + (R n - N) = M N + R n ) 2.If M >= N, the sum will produce an end carry R n and is discarded, result M - N is left 3.If M < N, the sum does not produce an end carry and is equal to R n - (N - M) which is R s complement of (N - M). Take R s complement of the sum and place a negative sign in front KSB-1601-07 31

Example 1.The subtraction of 72532 13250 = 59282 The 10 s complement of 13250 is 86750 M = 72532 10 s complement of N = +86750 Sum = 159282 Discard end carry 10 5 = -100000 Answer = 59282 KSB-1601-07 32

Example (contd..) 2.The subtraction of 13250 72532= - 59282 The 10 s complement of 72532 is 27468 M = 13250 10 s complement of N =+27468 Sum = 40718 There is no end carry Answer is 10 s complement of 40718 with a negative sign = - 59282 KSB-1601-07 33

Example (contd..) 3. X = 1010100 and Y = 1000011 we will perform X Y and Y - X X = 1010100 2 s complement of Y = 0111101 ----------------- Sum = 10010001 Discard end carry, Answer= 0010001 Y = 1000011 2 s complement of X = 0101100 ----------------- Sum = 1101111 There is no end carry carry, Answer= 0010001 which is 2 s complement of 1101111 KSB-1601-07 34

Exercise 5 1.Perform subtraction with the following unsigned numbers by taking 10 s complement of subtrahend A.5250-1321 B.1753-8640 C.20-100 D.1200-250 2.Perform subtraction with the following unsigned numbers by taking 2 s complement of subtrahend A.11010-10000 B.11010-1101 C.100-110000 D.1010100-1010100 KSB-1601-07 35

3. Fixed Point Representation In ordinary arithmetic, negative number is indicated by a minus sign and a positive number is indicated by a plus sign In computer representation this sign bit also should be represented by 0 s and 1 s Usually the sign is represented with a bit placed in the left most position of the number Convention is to make sign bit equal to 0 for positive and 1 for negative KSB-1601-07 36

Binary Point Number may have binary point also binary point is needed to represent integers, fractions or mixed integer fraction numbers There are two ways of specifying the position of the binary point in a register: by giving it a fixed position or floating point representation Fixed point method assumes that the binary point is always fixed in one position like 1. A binary point in the extreme left of the register to make the stored number a fraction 2. A binary point in the extreme right of the register to make the stored number an integer KSB-1601-07 37

Integer Representation When the integer number is positive, the sign is represented by 0, and the magnitude by a positive binary number When the number is negative, the sign is represented by 1 and the rest of the number is represented in one of the following ways: 1.Signed magnitude representation 2.Signed 1's complement representation 3.Signed 2's complement representation KSB-1601-07 38

Integer Representation (contd..) 1. Signed-magnitude representation: of a negative number consists of a negative sign(1) and magnitude Example: Store -14 in an 8 bit register Answer : Step1: Convert +14 to binary using 8 bits, keeping the MSB for sign (0 for positive) 0 000 1110 Step2: Now complement only the sign bit 1 000 1110 This is the signed magnitude representation of -14 KSB-1601-07 39

Integer Representation (contd..) 2. Signed-1 s complement representation: of a negative number is obtained by taking 1 s complement of its positive value Example: Store -14 in an 8 bit register Answer : Step1: Convert +14 to binary using 8 bits, keeping the MSB for sign (0 for positive) 0 000 1110 Step2: Now take 1 s complement 1 1110001 This is the signed 1 s complement representation of -14 KSB-1601-07 40

Integer Representation (contd..) 3. Signed-2 s complement representation: of a negative number is obtained by taking 2 s complement of its positive value Example: Store -14 in an 8 bit register Answer : Step1: Convert +14 to binary using 8 bits, keeping the MSB for sign (0 for positive) 0 000 1110 Step2: Now take 2 s complement 1 1110010 This is the signed 2 s complement representation of -14 KSB-1601-07 41

Integer Representation (contd..) 1.Signed-magnitude numbers : Binary Decimal Equivalent 00000000 0 00000001 +1 -- -- 01111110 +126 01111111 +127 10000000 0 10000001-1 -- -- 11111110-126 11111111-127 KSB-1601-07 42

Integer Representation (contd..) 2.1 s Complement numbers : Binary Decimal Equivalent 00000000 0 00000001 +1 -- -- 01111110 +126 01111111 +127 10000000-127 10000001-126 -- -- 11111110-1 11111111 0 KSB-1601-07 43

Integer Representation (contd..) 3. 2 s Complement numbers : Binary Decimal Equivalent 00000000 0 00000001 +1 -- -- 01111110 +126 01111111 +127 10000000-128 10000001-127 -- -- 11111110-2 11111111-1 Note: Negative number is binary equivalent of 2 n - N KSB-1601-07 44

Integer Representation (contd..) Maximum and Minimum representable numbers and representation of Zero: Assume the given number is represented by N = x n x n-1... x 0. x -1... x -m 1.Signed Magnitude Max: 011... 11.11... 1 Min: 111... 11.11... 1 Zero: +0 000... 00.00... 0-0 100... 00.00... 0 KSB-1601-07 45

Integer Representation (contd..) 2.Signed 1 s Complement Max: 011... 11.11... 1 Min: 100... 00.00... 0 Zero: +0 000... 00.00... 0-0 111... 11.11... 1 3.Signed 2 s Complement Max: 011... 11.11... 1 Min: 100... 00.00... 0 Zero: 0 000... 00.00... 0 KSB-1601-07 46

Integer Representation (contd..) Signed magnitude system is used in ordinary arithmetic but is awkward when employed in computer arithmetic hence not used in computers 1 s complement imposes difficulties because it has two representations of 0 (+0 and -0) hence this is also not used in computers although it is useful as a logical operation 2 s complement number system alone is used in computers KSB-1601-07 47

2 s Complement Addition / Subtraction Rules: for addition of two numbers 1.Always represent negative numbers in 2 s complement system 2.Add the two numbers including their sign bits 3.Discard any carry out of the sign (left most) bit position 4.If the sum obtained after addition is negative (i.e sign bit is 1), then the number is in 2 s complement form Rules: for subtraction of two numbers 1.For subtraction take the 2 s complement of the subtrahend and proceed as if it is addition ( above 4 steps) KSB-1601-07 48

Overflow When two numbers of n bits each are added and the sum occupies n+1 digits, we say overflow has occurred Overflow is a problem in digital computers because the width of registers is finite Detection of overflow after addition of two binary numbers depends on whether numbers are unsigned or signed In unsigned addition, carry out of MSB indicates overflow In signed addition as the MSB is sign bit, carry out of MSB does not indicate overflow KSB-1601-07 49

Overflow (contd..) Consider any number (in this case it is integer): X n X n-1 X n-2 ------ X 1 X 0 Sign bit (MSB) Penultimate bit (Next to MSB) Overflow = C s ( XOR ) C p Where C s is the carry from sign bit and C p is the carry from penultimate bit Note: Overflow can not occur after addition if one number is positive and the other is negative. Overflow may occur if both numbers are positive or negative KSB-1601-07 50

Exercise 6 1.Perform the arithmetic operations (+42) + (-13) and (-42) + (-13) in binary using 2 s complement representation for negative numbers 2.Perform the arithmetic operations (+70) + (+80) and (-70) + (-80) in binary using 2 s complement representation for negative numbers.use 8 bits to accommodate each number together with its sign KSB-1601-07 51

Exercise 6 (contd..) 3.Perform the arithmetic operations (+70) + (+80) and (-70) + (-80) in binary using 2 s complement representation for negative numbers. Use 8 bits to accommodate each number together with its sign. Show that overflow occurs in both cases, that the last two carries are unequal that there is sign reversal 4.Perform the following arithmetic operations with the decimal numbers using signed-10 s complement representation for negative numbers a) (-638) + (+785) b) (-638) (+185) KSB-1601-07 52