Complement Numbers. Outline  Negative Numbers Representation  Sign-and-magnitude  1s Complement  2s Complement  Comparison of Sign-and-Magnitude.

Slides:



Advertisements
Similar presentations
ELEC353 S. al Zahir UBC Sign-Magnitude Representation High order bit is sign: 0 = positive (or zero), 1 = negative Low order bits represent the magnitude:
Advertisements

COE 202: Digital Logic Design Signed Numbers
James Tam Numerical Representations On The Computer: Negative And Rational Numbers How are negative and rational numbers represented on the computer? How.
Wakerly Section 2.4 and further Addition and Subtraction of Nondecimal Numbers.
MOHD. YAMANI IDRIS/ NOORZAILY MOHAMED NOOR 1 Negative Number (Sign & Magnitude) Negative number always written with sign at the front: –Example: -(20)
CS 151 Digital Systems Design Lecture 3 More Number Systems.
Fixed-Point Arithmetics: Part I
1 Binary Arithmetic, Subtraction The rules for binary arithmetic are: = 0, carry = = 1, carry = = 1, carry = = 0, carry =
CSCE 211: Digital Logic Design Chin-Tser Huang University of South Carolina.
Number Representation (1) Fall 2005 Lecture 12: Number Representation Integers and Computer Arithmetic.
CS2100 Computer Organisation
CS1104: Computer Organisation comp. nus. edu
DIGITAL SYSTEMS TCE1111 Representation and Arithmetic Operations with Signed Numbers Week 6 and 7 (Lecture 1 of 2)
Complements: different approaches for representing negative numbers
ENGIN112 L3: More Number Systems September 8, 2003 ENGIN 112 Intro to Electrical and Computer Engineering Lecture 3 More Number Systems.
Data Representation – Chapter 3 Sections 3-2, 3-3, 3-4.
Chapter 3 Data Representation part2 Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2010.
Fixed-Point Negative Numbers Two Common Forms: 1.Signed-Magnitude Form 2.Complement Forms Signed-Magnitude Numbers First Digit is Sign Digit, Remaining.
NEGATIVE BINARY NUMBER – Digital Circuit 1 Choopan Rattanapoka.
Lecture 12: Computer Arithmetic Today’s topic –Numerical representations –Addition / Subtraction –Multiplication / Division 1.
Computer Organization & Programming Chapter2 Number Representation and Logic Operations.
Data Representation – Binary Numbers
#1 Lec # 2 Winter EECC341 - Shaaban Positional Number Systems A number system consists of an order set of symbols (digits) with relations.
Chapter 4 – Arithmetic Functions and HDLs Logic and Computer Design Fundamentals.
CPS120: Introduction to Computer Science Computer Math: Signed Numbers.
Calculating Two’s Complement. The two's complement of a binary number is defined as the value obtained by subtracting the number from a large power of.
1 Digital Design: Number Systems Credits : Slides adapted from: J.F. Wakerly, Digital Design, 4/e, Prentice Hall, 2006 C.H. Roth, Fundamentals of Logic.
Engineering 1040: Mechanisms & Electric Circuits Spring 2014 Number Systems.
Computer Number Systems. d n-1 d n-2 d n d 2-m d 1-m d -m Conventional Radix Number r is the radixd i is a digit d i Є {0, 1, ….., r – 1 } -m ≤
Number Systems and Codes. CS2100 Number Systems and Codes 2 NUMBER SYSTEMS & CODES Information Representations Number Systems Base Conversion Negative.
ECE 301 – Digital Electronics Unsigned and Signed Numbers, Binary Arithmetic of Signed Numbers, and Binary Codes (Lecture #2)
Number Representation
ECE2030 Introduction to Computer Engineering Lecture 2: Number System Prof. Hsien-Hsin Sean Lee School of Electrical and Computer Engineering Georgia Tech.
ECE 2110: Introduction to Digital Systems Signed Addition/Subtraction.
Floating Point Arithmetic
Chapter 3 Complements Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2009.
Digital Logic Lecture 3 Binary Arithmetic By Zyad Dwekat The Hashemite University Computer Engineering Department.
CEC 220 Digital Circuit Design Binary Arithmetic & Negative Numbers Monday, January 13 CEC 220 Digital Circuit Design Slide 1 of 14.
CEC 220 Digital Circuit Design Binary Arithmetic & Negative Numbers Fri, Aug 28 CEC 220 Digital Circuit Design Slide 1 of 14.
Representing Integer Data
IT1004: Data Representation and Organization Negative number representation.
ECE 171 Digital Circuits Chapter 2 Binary Arithmetic Herbert G. Mayer, PSU Status 1/14/2016 Copied with Permission from prof. Mark PSU ECE.
ECE DIGITAL LOGIC LECTURE 3: DIGITAL COMPUTER AND NUMBER SYSTEMS Assistant Prof. Fareena Saqib Florida Institute of Technology Fall 2016, 01/19/2016.
In decimal we are quite familiar with placing a “-” sign in front of a number to denote that it is negative The same is true for binary numbers a computer.
ECEN 248: INTRODUCTION TO DIGITAL SYSTEMS DESIGN Lecture 8 Dr. Shi Dept. of Electrical and Computer Engineering.
1 CS 151 : Digital Design Chapter 4: Arithmetic Functions and Circuits 4-3 : Binary Subtraction.
ECE 3110: Introduction to Digital Systems Number Systems: signed numbers.
Integer Operations Computer Organization and Assembly Language: Module 5.
Computer Organization 1 Data Representation Negative Integers.
ECE 3110: Introduction to Digital Systems Signed Number Conversions and operations.
COSC2410: LAB 2 BINARY ARITHMETIC SIGNED NUMBERS FLOATING POINT REPRESENTATION BOOLEAN ALGEBRA 1.
Lecture 4: Digital Systems & Binary Numbers (4)
DIGITAL Logic DESIGN Digital system and binary numbers Lecturer: Ms. Farwah Ahmad.
1 CE 454 Computer Architecture Lecture 4 Ahmed Ezzat The Digital Logic, Ch-3.1.
CPE 201 Digital Design Lecture 3: Digital Systems & Binary Numbers (3)
CS2100 Computer Organisation
Design of Digital Circuits Reading: Binary Numbers
Addition and Subtraction
CS2100 Computer Organisation
CHAPTER 9 COMPUTER ARITHMETIC - ALU
Negative Binary Numbers
Lecture 2 Topics Binary Arithmetic (Unsigned binary operands)
Negative Binary Numbers
CS1010 Programming Methodology
ECE 2110: Introduction to Digital Systems
Lecture 2 Topics Binary Arithmetic (Unsigned binary operands)
Data Representation in Computer Systems
ECE 3110: Introduction to Digital Systems
ECE 171 Digital Circuits Chapter 2 Binary Arithmetic
COMS 361 Computer Organization
Presentation transcript:

Complement Numbers

Outline  Negative Numbers Representation  Sign-and-magnitude  1s Complement  2s Complement  Comparison of Sign-and-Magnitude and Complements  Complements  Diminished-Radix Complements  Radix Complements  2’s Complement Addition and Subtraction  1’s Complement Addition and Subtraction

Outline  Negative Numbers Representation  Sign-and-magnitude  1s Complement  2s Complement  Comparison of Sign-and-Magnitude and Complements  Complements  Diminished-Radix Complements  Radix Complements  2’s Complement Addition and Subtraction  1’s Complement Addition and Subtraction

Negative Numbers Representation  Till now, we have only considered how unsigned (non- negative) numbers can be represented. There are three common ways of representing signed numbers (positive and negative numbers) for binary numbers:  Sign-and-Magnitude  1s Complement  2s Complement

Negative Numbers: Sign-and-Magnitude  Negative numbers are usually written by writing a minus sign in front.  Example: - (12) 10, - (1100) 2  In computer memory of fixed width, this sign is usually represented by a bit: 0 for + 1 for -

Negative Numbers: Sign-and-Magnitude  Example: an 8-bit number can have 1-bit sign and 7-bits magnitude. sign magnitude

Negative Numbers: Sign-and-Magnitude  Largest Positive Number: (127) 10  Largest Negative Number: (127) 10  Zeroes: (0) (0) 10  Range: - (127) 10 to +(127) 10

Negative Numbers: Sign-and-Magnitude  To negate a number, just invert the sign bit.  Examples: - ( ) sm  ( ) sm - ( ) sm  ( ) sm

1s and 2s Complement  Two other ways of representing signed numbers for binary numbers are:  1s-complement  2s-complement

1s Complement  Given a number x which can be expressed as an n-bit binary number, its negative value can be obtained in 1s-complement representation using: - x = 2 n - x - 1 Example: With an 8-bit number , its negative value, expressed in 1s complement, is obtained as follows: -( ) 2 = - (12) 10 = ( ) 10 = (243) 10 = ( ) 1s

1s Complement  Essential technique: invert all the bits. Examples: 1s complement of ( ) 1s = ( ) 1s 1s complement of ( ) 1s = ( ) 1s  Largest Positive Number: (127) 10  Largest Negative Number: (127) 10  Zeroes:  Range: -(127) 10 to +(127) 10  The most significant bit still represents the sign: 0 = +ve; 1 = -ve.

1s Complement  Examples (assuming 8-bit binary numbers): (14) 10 = ( ) 2 = ( ) 1s -(14) 10 = -( ) 2 = ( ) 1s -(80) 10 = -( ? ) 2 = ( ? ) 1s

2s Complement  Given a number x which can be expressed as an n-bit binary number, its negative number can be obtained in 2s-complement representation using: - x = 2 n - x Example: With an 8-bit number , its negative value in 2s complement is thus: -( ) 2 = - (12) 10 = ( ) 10 = (244) 10 = ( ) 2s

2s Complement  Essential technique: invert all the bits and add 1. Examples: 2s complement of ( ) 2s = ( ) 1s (invert) = ( ) 2s (add 1) 2s complement of ( ) 2s = ( ) 1s (invert) = ( ) 2s (add 1)

2s Complement  Largest Positive Number: (127) 10  Largest Negative Number: (128) 10  Zero:  Range: -(128) 10 to +(127) 10  The most significant bit still represents the sign: 0 = +ve; 1 = -ve.

2s Complement  Examples (assuming 8-bit binary numbers): (14) 10 = ( ) 2 = ( ) 2s -(14) 10 = -( ) 2 = ( ) 2s -(80) 10 = -( ? ) 2 = ( ? ) 2s

Outline  Negative Numbers Representation  Sign-and-magnitude  1s Complement  2s Complement  Comparison of Sign-and-Magnitude and Complements  Complements  Diminished-Radix Complements  Radix Complements  2’s Complement Addition and Subtraction  1’s Complement Addition and Subtraction

Comparisons of Sign-and-Magnitude and Complements  Example: 4-bit signed number ()  Example: 4-bit signed number (positive values)

Comparisons of Sign-and-Magnitude and Complements  Example: 4-bit signed number ()  Example: 4-bit signed number (negative values)

Outline  Negative Numbers Representation  Sign-and-magnitude  1s Complement  2s Complement  Comparison of Sign-and-Magnitude and Complements  Complements  Diminished-Radix Complements  Radix Complements  2’s Complement Addition and Subtraction  1’s Complement Addition and Subtraction

Complements (General)  Complement numbers can help perform subtraction. With complements, subtraction can be performed by addition. Hence, A – B can be performed by A + (-B) where (-B) is represented as the complement of B.  In general for Base-r number, there are: (i) Diminished Radix (or r-1’s) Complement (ii) Radix (or r’s) Complement  For Base-2 number, we have seen: (i) 1s Complement (ii) 2s Complement

Diminished-Radix Complements  Given an n-digit number, x r, its (r-1)’s complement is: (r n - 1) – x (r-1)’s complement, or 9s complement, of (22) 10 is: ( ) - 22 = (77) 9s [This means –(22) 10 is (77) 9s ] (r-1)’s complement, or 1s complement, of (0101) 2 is: ( ) = (1010) 1s [This means –(0101) 2 is (1010) 1s ] Same as inverting all digits: ( ) - 22 = = (77) 9s ( ) = = (1010) 1s

Radix Complements  Given an n-digit number, x r, its r’s-complement is: r n – x r’s-complement, or 10s complement, of (22) 10 is: = (78) 10s [This means –(22) 10 is (78) 10s ] r’s-complement, or 2s complement, of (0101) 2 is: = (1011) 2s [This means –(0101) 2 is (1011) 2s ] Same as inverting all digits and adding 1: (10 2 ) - 22 = (99+1) - 22 = = (78) 10s (2 4 ) = (1111+1) = = (1011) 2s

Outline  Negative Numbers Representation  Sign-and-magnitude  1s Complement  2s Complement  Comparison of Sign-and-Magnitude and Complements  Complements  Diminished-Radix Complements  Radix Complements  2’s Complement Addition and Subtraction  1’s Complement Addition and Subtraction

2s Complement Addition/Subtraction  Algorithm for addition, A + B: 1.Perform binary addition on the two numbers. 2.Ignore the carry out of the MSB (most significant bit). 3.Check for overflow: Overflow occurs if the ‘carry in’ and ‘carry out’ of the MSB are different, or if result is opposite sign of A and B.  Algorithm for subtraction, A – B: A – B = A + (–B) 1.Take 2s complement of B by inverting all the bits and adding 1. 2.Add the 2s complement of B to A.

2s Complement Addition/Subtraction  Examples: 4-bit binary system  Which of the above is/are overflow(s)?

2s Complement Addition/Subtraction  More examples: 4-bit binary system  Which of the above is/are overflow(s)?

Outline  Negative Numbers Representation  Sign-and-magnitude  1s Complement  2s Complement  Comparison of Sign-and-Magnitude and Complements  Complements  Diminished-Radix Complements  Radix Complements  2’s Complement Addition and Subtraction  1’s Complement Addition and Subtraction

1s Complement Addition/Subtraction  Algorithm for addition, A + B: 1.Perform binary addition on the two numbers. 2.If there is a carry out of the MSB, add 1 to the result. 3.Check for overflow: Overflow occurs if result is opposite sign of A and B.  Algorithm for subtraction, A – B: A – B = A + (–B) 1.Take 1s complement of B by inverting all the bits. 2.Add the 1s complement of B to A.

1s Complement Addition/Subtraction  Examples: 4-bit binary system