Representing Negative Numbers Noah Mendelsohn Tufts University Web: COMP 40: Machine.

Slides:



Advertisements
Similar presentations
COE 202: Digital Logic Design Signed Numbers
Advertisements

Binary Representation Introduction to Computer Science and Programming I Chris Schmidt.
1 CSE1301 Computer Programming Lecture 29: Number Representation (Part 1)
James Tam Numerical Representations On The Computer: Negative And Rational Numbers How are negative and rational numbers represented on the computer? How.
Cpe 252: Computer Organization1 Lo’ai Tawalbeh Lecture #2 Standard combinational modules: decoders, encoders and Multiplexers 1/3/2005.
J. Michael Moore Computer Organization CSCE 110. J. Michael Moore High Level View Of A Computer ProcessorInputOutput Memory Storage.
CS 151 Digital Systems Design Lecture 3 More Number Systems.
Representations Example: Numbers –145 –CVL – –91 –
Agenda Shortcuts converting among numbering systems –Binary to Hex / Hex to Binary –Binary to Octal / Octal to Binary Signed and unsigned binary numbers.
Signed Numbers Up till now we've been concentrating on unsigned numbers. In real life we have to represent signed numbers ( like: -12, -45, 78). The difference.
Professor Jennifer Rexford COS 217
ENGIN112 L3: More Number Systems September 8, 2003 ENGIN 112 Intro to Electrical and Computer Engineering Lecture 3 More Number Systems.
CSE20 Lecture 3 Number Systems: Negative Numbers 1.Sign and Magnitude Representation 2.1’s Complement Representation 3.2’s Complement Representation 1.
Number Systems Lecture 02.
3. Representing Integer Data
Computer Organization & Programming Chapter2 Number Representation and Logic Operations.
IEEE Floating Point Numbers Overview Noah Mendelsohn Tufts University Web: COMP.
© Janice Regan, CMPT 128, Jan CMPT 128: Introduction to Computing Science for Engineering Students Integer Data representation Addition and Multiplication.
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
CENG 311 Machine Representation/Numbers
Simple Data Type Representation and conversion of numbers
Lecture 5.
CMPT 120 How computers run programs Summer 2012 Instructor: Hassan Khosravi.
CS Binary Representation of Information Detecting Voltage Levels Why not 10 levels? Would be unreliable Not enough difference between states On/Off.
1 Digital Systems and Binary Numbers EE 208 – Logic Design Chapter 1 Sohaib Majzoub.
Topic: Arithmetic Circuits Course: Digital Systems Slide no. 1 Chapter # 5: Arithmetic Circuits.
1 COMS 161 Introduction to Computing Title: Numeric Processing Date: October 20, 2004 Lecture Number: 23.
Number Systems. Today Decimal Hexadecimal Binary –Unsigned Binary –1’s Complement Binary –2’s Complement Binary.
Positional Number Systems
Number Representation
Lecture 2 Binary Values and Number Systems. The number 943 is an example of a number written in positional notation. The relative positions of the digits.
Number Systems and Logic Prepared by Dr P Marais (Modified by D Burford)
INEL 4215: Computer Architecture and Organization Number Systems Signed numbers.
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.
Big Endian vs. Little Endian Storage of Numeric Data Noah Mendelsohn Tufts University Web:
07/12/ Data Representation Two’s Complement & Binary Arithmetic.
Introduction to Microprocessors Chapter 2. Decimal or Base 10 Numbers  Have ten different digits (0-9)  It is a weighted number system. Each position.
Digital Representations ME 4611 Binary Representation Only two states (0 and 1) Easy to implement electronically %0= (0) 10 %1= (1) 10 %10= (2) 10 %11=
Building Your Own Machine The Universal Machine (UM) Introduction Noah Mendelsohn Tufts University Web:
CS1Q Computer Systems Lecture 2 Simon Gay. Lecture 2CS1Q Computer Systems - Simon Gay2 Binary Numbers We’ll look at some details of the representation.
Bits, Data types, and Operations: Chapter 2 COMP 2610 Dr. James Money COMP
CPS3340 Computer Architecture Fall Semester, 2013
IT1004: Data Representation and Organization Negative number representation.
1 COMS 161 Introduction to Computing Title: Computing Basics Date: September 8, 2004 Lecture Number: 7.
Two’s and one’s complement arithmetic CLOCK ARITHMETIC.
Branch Addressing op rs rt address address beq $s1, $s2, Label if ($s1 = =$s2) go to Label 6 bits 5 bits 5 bits 16 bits effective 32 bit address.
Negative Integers Unsigned binary representation can not be used to represent negative numbers. With paper and pencil arithmetic, a number is made negative.
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 Ethics of Computing MONT 113G, Spring 2012 Session 4 Binary Addition.
ECE 3110: Introduction to Digital Systems Number Systems: signed numbers.
Integer Operations Computer Organization and Assembly Language: Module 5.
09/03/20161 Information Representation Two’s Complement & Binary Arithmetic.
Computer Organization 1 Data Representation Negative Integers.
Bits, Data types, and Operations: Chapter 2 COMP 2610 Dr. James Money COMP
Nguyen Le CS147.  2.4 Signed Integer Representation  – Signed Magnitude  – Complement Systems  – Unsigned Versus Signed Numbers.
1 Integer Representations V1.0 (22/10/2005). 2 Integer Representations  Unsigned integer  Signed integer  Sign and magnitude  Complements  One’s.
Binary Arithmetic James A. Rome Tennessee Governor's Academy August 2010.
Binary Addition The simplest arithmetic operation in binary is addition. Adding two single-digit binary numbers is relatively simple, using a form of carrying:
Design of Digital Circuits Reading: Binary Numbers
David Kauchak CS 52 – Spring 2017
Computer Architecture & Operations I
Negative Integers Unsigned binary representation can not be used to represent negative numbers. With paper and pencil arithmetic, a number is made negative.
Negative Binary Numbers
Hexadecimal, Signed Numbers, and Arbitrariness
Computer Architecture & Operations I
Negative Binary Numbers
EEL 3705 / 3705L Digital Logic Design
CSC 220: Computer Organization Signed Number Representation
Today Binary addition Representing negative numbers 2.
Presentation transcript:

Representing Negative Numbers Noah Mendelsohn Tufts University Web: COMP 40: Machine Structure and Assembly Language Programming (Fall 2014)

© 2010 Noah Mendelsohn Goals for this presentation  Discuss the representation of variables that can take negative or positive values (or zero, of course!)  Develop your intuition about why 2’s complement arithmetic works 2

© 2010 Noah Mendelsohn Representing Negative Numbers

© 2010 Noah Mendelsohn Bits mean nothing on their own…  What's this: ?  Ideas? –Positive integer 244 –HALT instruction (CPU idle) –Negative integer -12 –Small o with hat (circumflex) –0.957 pixel brightness (scaled by 255) –bit vector  With 8 bits we can distinguish 256 choices –If we use some bit patterns for negative numbers… –…then those same patterns can no longer stand for positives! 4 Question…what’s the best representation for negative numbers?

© 2010 Noah Mendelsohn At least three ways to represent negative numbers  Use the high order bit as a sign (sign and magnitude) –  Flip all the bits for negative (ones’ complement) –  Flip all bits then add one (two’s complement) – We usually represent the number 5 as How should we represent -5?

© 2010 Noah Mendelsohn At least three ways to represent negative numbers  Use the high order bit as a sign (sign and magnitude) –  Flip all the bits for negative (ones’ complement) –  Flip all bits then add one (two’s complement) – We usually represent the number 5 as How should we represent -5? These seem obvious and simple… …but there are problems For example, both representations have separate representations of +0 and -0, which makes it hard to implement sequences like: x = (-3); x = x + 5;

© 2010 Noah Mendelsohn At least three ways to represent negative numbers  Use the high order bit as a sign (sign and magnitude) –  Flip all the bits for negative (ones’ complement) –  Flip all bits then add one (two’s complement) – We usually represent the number 5 as How should we represent -5? Two’s complement is trickier to learn… … but it doesn’t have these problems. In fact, two’s complement has many advantages, and almost all modern computers use it!

© 2010 Noah Mendelsohn Odometer Arithmetic Modular Number Systems

© 2010 Noah Mendelsohn The problem:  I get why: 2 is encoded as  I have no clue why: -2 is encoded as

© 2010 Noah Mendelsohn Modular arithmetic 10 What happens when this goes past ? = 0 So, what should 0-1 be?

© 2010 Noah Mendelsohn Modular arithmetic – mod

© 2010 Noah Mendelsohn Modular arithmetic – mod

© 2010 Noah Mendelsohn Unsigned modular arithmetic – mod

© 2010 Noah Mendelsohn Signed modular arithmetic – mod

© 2010 Noah Mendelsohn The 2s complement magic 15 The hardware does the same thing, only the interpretatation is different!

© 2010 Noah Mendelsohn Polynomials

© 2010 Noah Mendelsohn Binary numbers encode coefficients of polynomials 17 0 x x x x x x x x 2 0 =

© 2010 Noah Mendelsohn Two’s complement numbers as polynomial coefficients x x x x x x x x 2 0 = = -5 Hi order digit subtracted, all others added!

© 2010 Noah Mendelsohn Try it with -1 in two’s complement =