Negative Bit Representation Outline

Slides:



Advertisements
Similar presentations
Integers. Integer Storage Since Binary consists only of 0s and 1s, we can’t use a negative sign ( - ) for integers. Instead, the Most Significant Bit.
Advertisements

King Fahd University of Petroleum and Minerals
CS 151 Digital Systems Design Lecture 3 More Number Systems.
ENGIN112 L3: More Number Systems September 8, 2003 ENGIN 112 Intro to Electrical and Computer Engineering Lecture 3 More Number Systems.
Signed Numbers CS208. Signed Numbers Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers.
IT253: Computer Organization
+ CS 325: CS Hardware and Software Organization and Architecture Integers and Arithmetic Part 2.
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.
Representation of Data Ma King Man. Reference Text Book: Volume 2 Notes: Chapter 19.
Cosc 2150: Computer Organization Chapter 2 Part 1 Integers addition and subtraction.
Negative Bit Representation Lesson CS1313 Spring Negative Bit Representation Outline 1.Negative Bit Representation Outline 2.Negative Integers 3.Representing.
Chapter 3 Complements Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2009.
By Jariya Phongsai A two's-complement system is a system in which negative numbers are represented by the two's complement of the absolute value; this.
Integer and Fixed Point P & H: Chapter 3
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.
1 Digital Logic Design Lecture 2 More Number Systems/Complements.
Computer Organization 1 Data Representation Negative Integers.
COSC2410: LAB 2 BINARY ARITHMETIC SIGNED NUMBERS FLOATING POINT REPRESENTATION BOOLEAN ALGEBRA 1.
Cosc 2150: Computer Organization Chapter 9, Part 3 Floating point numbers.
Lecture 4: Digital Systems & Binary Numbers (4)
Representing Positive and Negative Numbers
1 CE 454 Computer Architecture Lecture 4 Ahmed Ezzat The Digital Logic, Ch-3.1.
Floating Point Numbers Dr. Mohsen NASRI College of Computer and Information Sciences, Majmaah University, Al Majmaah
Computer Representation of Information
Floating Point Representations
Cosc 2150: Computer Organization
Backgrounder: Binary Math
Design of Digital Circuits Reading: Binary Numbers
David Kauchak CS 52 – Spring 2017
Dr.Faisal Alzyoud 2/20/2018 Binary Arithmetic.
Computer Architecture & Operations I
Addition and Subtraction
Data Representation.
Binary -ve and +ve numbers!.
Dr. Clincy Professor of CS
Digital Logic & Design Dr. Waseem Ikram Lecture 02.
Integer Real Numbers Character Boolean Memory Address CPU Data Types
Computer Science 210 Computer Organization
Data Representation in Computer Systems
Section 2: Integer & Floating Point Numbers
Computer Architecture & Operations I
Lecture 2 Topics Binary Arithmetic (Unsigned binary operands)
Data Structures Mohammed Thajeel To the second year students
Lecture 2 Topics Binary Arithmetic (Unsigned binary operands)
MIPS ALU.
Computer Science 210 Computer Organization
COMPLEMENTS Complements are used in digital computers for simplifying the subtraction operations and for logical manipulation. There are two types of complements.
King Fahd University of Petroleum and Minerals
MIPS ALU.
Data Representation in Computer Systems
Topic 3a Two’s Complement Representation
Subtraction The arithmetic we did so far was limited to unsigned (positive) integers. Today we’ll consider negative numbers and subtraction. The main problem.
Fundamentals of Data Representation
Digital Logic & Design Lecture 02.
CS/COE0447 Computer Organization & Assembly Language
COMS 161 Introduction to Computing
CS/COE0447 Computer Organization & Assembly Language
CPS120: Introduction to Computer Science
Decimal and binary representation systems
Numbers representations
Binary to Decimal Conversion
ECE 331 – Digital System Design
CSC 220: Computer Organization Signed Number Representation
COMS 361 Computer Organization
Chapter3 Fixed Point Representation
MIPS ALU.
MIPS ALU.
Two’s Complement & Binary Arithmetic
Presentation transcript:

Negative Bit Representation Outline Negative Integers Representing Negativity Which Bit for the Sign? Sign-Value Disadvantages of Sign-Value One’s Complement Disadvantages of One’s Complement Two’s Complement Advantages of Two’s Complement #1 Advantages of Two’s Complement #2 Advantages of Two’s Complement #3 Advantages of Two’s Complement #4 Range of Two’s Complement Values #1 Range of Two’s Complement Values #2 Range of Two’s Complement Values #3 Range of Two’s Complement Values #4 Range of Two’s Complement Values #5 Overflow #1 Overflow #2 Underflow #1 Underflow #2 Negative Bit Representation Lesson CS1313 Spring 2009

Negative Bit Representation Lesson Negative Integers In the first slide packet on binary representation, we saw how nonnegative integer values like 97 are represented in memory. What if, instead of having 97, we had -97? We need a way to represent negative integers. Negative Bit Representation Lesson CS1313 Spring 2009

Representing Negativity For starters, we need a way to represent whether an integer is negative or positive. We can think of this as a binary question: a number is either negative or nonnegative. So, we can simply pick a bit in the binary representation of the integer and decide that it’s going to be the sign bit. Which bit should we pick? Negative Bit Representation Lesson CS1313 Spring 2009

Negative Bit Representation Lesson Which Bit for the Sign? Which bit should we pick? Well, we want to pick the bit that we’re least likely to use in real life, so that it’s not a big waste to use it as a sign bit. In real life, we’re much more likely to deal with very small numbers (for example, 0, 1, 13, 97) than very large numbers (for example, 4001431453). So, we pick the leftmost bit, called the most significant bit, and decide that it’ll be our sign bit. Negative Bit Representation Lesson CS1313 Spring 2009

Negative Bit Representation Lesson Sign-Value Okay, now we have our sign bit. So here are three ways to represent negative integers. Sign-Value: To get the negative version of a positive number, set the sign bit to 1, and leave all other bits unchanged: 1 97 = -97 = Negative Bit Representation Lesson CS1313 Spring 2009

Disadvantages of Sign-Value An unfortunate feature of Sign-Value representation is that there are two ways of representing the value zero: all bits set to zero, and all bits except the sign bit set to zero. This makes the math a bit confusing. More importantly, when performing arithmetic operations, we need to treat negative operands as special cases. 0 = 1 Negative Bit Representation Lesson CS1313 Spring 2009

Negative Bit Representation Lesson One’s Complement One’s Complement: To get the negative version of a positive number, invert (complement) all bits; that is, all 1’s become 0’s and vice versa. 1 97 = -97 = Negative Bit Representation Lesson CS1313 Spring 2009

Disadvantages of One’s Complement An unfortunate feature of One’s Complement representation is that there are two ways of representing the value zero: all bits set to zero, and all bits set to one. This makes the math a bit confusing. More importantly, when performing arithmetic operations, we need to treat negative operands as special cases. 0 = 1 Negative Bit Representation Lesson CS1313 Spring 2009

Negative Bit Representation Lesson Two’s Complement Two’s Complement: To get the negative version of a positive number, invert all bits and then add 1; if the addition causes a carry bit past the most significant bit, discard the high carry: 1 97 = 1 ~97 = + 1 1 -97 = Negative Bit Representation Lesson CS1313 Spring 2009

Advantages of Two’s Complement #1 In Two’s Complement representation, the value zero is uniquely represented by having all bits set to zero: 0 = 1 ~0 = -0 = + 1 1 Negative Bit Representation Lesson CS1313 Spring 2009

Advantages of Two’s Complement #2 When you perform an arithmetic operation (for example, addition, subtraction, multiplication, division) on two signed integers in Two’s Complement representation, you can use exactly the same method as if you had two unsigned integers (that is, nonnegative integers with no sign bit) ... EXCEPT, you throw away the high carry (or the high borrow for subtraction). Negative Bit Representation Lesson CS1313 Spring 2009

Advantages of Two’s Complement #3 This property of Two’s Complement representation is so incredibly handy that virtually every general-purpose computer available today uses Two’s Complement. Why? Because, with Two’s Complement, we don’t need special algorithms for arithmetic operations that involve negative values. Negative Bit Representation Lesson CS1313 Spring 2009

Advantages of Two’s Complement #4 Using Two’s Complement to do arithmetic: 1 97 = 1 -97 = 1 0 = Negative Bit Representation Lesson CS1313 Spring 2009

Advantages of Two’s Complement #4 Using Two’s Complement to do arithmetic: 1 45 = -14 = 31 = 1 Negative Bit Representation Lesson CS1313 Spring 2009

Range of Two’s Complement Values #1 When we represent negative integers in Two’s Complement notation, the range of numbers that can be represented in b bits is: −(2b−1) . . . (+2b−1 − 1) For example, the range of numbers that can be represented in 8 bits is: −(27) . . . (+27 − 1) = −128 . . . 127 Likewise, the range of numbers that can be represented in 16 bits is: −(215) . . . (+215 − 1) = −32,768 . . . 32,767 How do we know this? Negative Bit Representation Lesson CS1313 Spring 2009

Range of Two’s Complement Values #2 When we represent negative integers in Two’s Complement notation, the range of numbers that can be represented in b bits is: −(2b−1) . . . (+2b−1 − 1) How do we know this? Here’s the biggest number that can be represented in 16 bits: If we add one to it, we get: But this number is negative. 1 1 Negative Bit Representation Lesson CS1313 Spring 2009

Range of Two’s Complement Values #3 Here’s the biggest number that can be represented in 16 bits: If we add one to it, we get: But this number is negative. If we ignore the sign, then it’s 215, which is 216-1, which is 2b-1, where b (the number of bits) is 16. Therefore, the largest number that can be represented in b bits in Two’s Complement must be 2b-1-1. 1 1 Negative Bit Representation Lesson CS1313 Spring 2009

Range of Two’s Complement Values #4 So what’s the smallest negative integer (that is, the negative integer with the greatest absolute value)? Well, can we represent the negative of 2b−1 − 1? 1 +(2b-1 – 1) = ~(2b-1 - 1) = 1 + 1 -(2b-1 - 1) = 1 Negative Bit Representation Lesson CS1313 Spring 2009

Range of Two’s Complement Values #5 We can represent –(2b−1 − 1). So, can we represent the negative of –(2b−1)? Since the sign didn’t change, it worked! But, if we tried subtracting again, we’d borrow and the sign would change, indicating failure. So, –(2b−1) is the lowest number that can be represented. 1 -(2b-1 - 1) = -(2b-1) = - 1 Negative Bit Representation Lesson CS1313 Spring 2009

Negative Bit Representation Lesson Overflow #1 When we’re working with a value that’s near the upper limit of what can be represented in Two’s Complement for the given number of bits, we sometimes perform an operation that should result in a positive value but instead produces a negative value. Such an event is called overflow. Negative Bit Representation Lesson CS1313 Spring 2009

Negative Bit Representation Lesson Overflow #2 Consider the following addition in 8-bit Two’s Complement representation: Notice that the result should be +128, but because the leftmost bit is 1, it’s actually -128. This is overflow: an arithmetic operation that should have a positive result goes over the top to become negative. 1 +127 = + 1 +128? = Negative Bit Representation Lesson CS1313 Spring 2009

Negative Bit Representation Lesson Underflow #1 When we’re working with a value that’s near the lower limit of what can be represented in Two’s Complement for the given number of bits, we sometimes perform an operation that should result in a negative value but instead produces a positive value. Such an event is called underflow. Negative Bit Representation Lesson CS1313 Spring 2009

Negative Bit Representation Lesson Underflow #2 Consider the following addition in 8-bit Two’s Complement representation: Notice that the result should be -129, but because the leftmost bit is 1, it’s actually +127. This is underflow: an arithmetic operation that should have a negative result goes under the bottom to become positive. 1 -128 = - 1 - 1 1 -129? = Negative Bit Representation Lesson CS1313 Spring 2009