07/12/20151 4.12 Data Representation Two’s Complement & Binary Arithmetic.

Slides:



Advertisements
Similar presentations
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.
Advertisements

HEXADECIMAL NUMBERS Code
Addition and Subtraction. Outline Arithmetic Operations (Section 1.2) – Addition – Subtraction – Multiplication Complements (Section 1.5) – 1’s complement.
DATA REPRESENTATION Y. Colette Lemard February
James Tam Numerical Representations On The Computer: Negative And Rational Numbers How are negative and rational numbers represented on the computer? How.
James Tam Numerical Representations On The Computer: Negative And Rational Numbers How are negative and rational numbers represented on the computer? How.
James Tam Numerical Representations On The Computer: Negative And Rational Numbers How are negative and rational numbers represented on the computer?
James Tam Number Representations You will learn about the binary number system and how subtractions are performed on the computer.
James Tam Numerical Representations On The Computer: Negative And Rational Numbers How are negative and rational numbers represented on the computer? How.
James Tam Numerical Representations On The Computer: Negative And Rational Numbers How are negative and rational numbers represented on the computer? How.
Assembly Language and Computer Architecture Using C++ and Java
Signed Numbers.
Assembly Language and Computer Architecture Using C++ and Java
Computer ArchitectureFall 2008 © August 25, CS 447 – Computer Architecture Lecture 3 Computer Arithmetic (1)
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.
Mathematics with Binary. Question  Below is a binary string  Which is the least significant bit (LSB)?  Which is the most significant bit (MSB)? 0.
Complements: different approaches for representing negative numbers
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.
Computer ArchitectureFall 2007 © August 29, 2007 Karem Sakallah CS 447 – Computer Architecture.
Two’s Complement 1.As an action: (Assume the starting value is 1011) 1.Flip the bits from the starting value => Add one to get the answer.
1 Binary Numbers Again Recall that N binary digits (N bits) can represent unsigned integers from 0 to 2 N bits = 0 to 15 8 bits = 0 to bits.
1 Lecture 2: Number Systems Binary numbers Base conversion Arithmetic Number systems  Sign and magnitude  Ones-complement  Twos-complement Binary-coded.
Chapter 3 Data Representation part2 Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2010.
Chapter3 Fixed Point Representation Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2009.
Computer Organization & Programming Chapter2 Number Representation and Logic Operations.
Lecture for Week Spring.  Numbers can be represented in many ways. We are familiar with the decimal system since it is most widely used in everyday.
NUMBER REPRESENTATION CHAPTER 3 – part 3. ONE’S COMPLEMENT REPRESENTATION CHAPTER 3 – part 3.
©Brooks/Cole, 2003 Chapter 3 Number Representation.
ECE 301 – Digital Electronics Unsigned and Signed Numbers, Binary Arithmetic of Signed Numbers, and Binary Codes (Lecture #2)
Cosc 2150: Computer Organization Chapter 2 Part 1 Integers addition and subtraction.
BR 8/99 Binary Numbers Again Recall than N binary digits (N bits) can represent unsigned integers from 0 to 2 N bits = 0 to 15 8 bits = 0 to 255.
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.
Computer Math CPS120 Introduction to Computer Science Lecture 4.
1 Positive numbers are well understood An n-bit number represents numbers from 0 to 2 n -1 n+m bits can be used to represent n-bit integer and m-bit fraction.
Data Representation in Computer Systems. 2 Signed Integer Representation The conversions we have so far presented have involved only positive numbers.
Two’s Complement. A system used to represent a negative number in binary A system used to represent a negative number in binary Positive numbers start.
Addition and Substraction
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=
Bits, Data types, and Operations: Chapter 2 COMP 2610 Dr. James Money COMP
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.
IT1004: Data Representation and Organization Negative number representation.
Integers’ Representation. Binary Addition. Two's Complement. Unsigned number representation Binary Addition, Subtraction. Overflow of unsigned numbers.
James Tam Numerical Representations On The Computer: Negative And Rational Numbers How are negative and rational numbers represented on the computer? How.
Two’s and one’s complement arithmetic CLOCK ARITHMETIC.
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.
09/03/20161 Information Representation Two’s Complement & Binary Arithmetic.
Computer Organization 1 Data Representation Negative Integers.
ECE 3110: Introduction to Digital Systems Signed Number Conversions and operations.
{ Binary “There are 10 types of people in the world: Those who understand binary, and those who don't.”
1 Integer Representations V1.0 (22/10/2005). 2 Integer Representations  Unsigned integer  Signed integer  Sign and magnitude  Complements  One’s.
Binary Addition The simplest arithmetic operation in binary is addition. Adding two single-digit binary numbers is relatively simple, using a form of carrying:
Advanced Binary b. describe and use two’s complement and sign and magnitude to represent negative integers; c. perform integer binary arithmetic, that.
Chapter 4 Operations on Bits.
CHAPTER 9 COMPUTER ARITHMETIC - ALU
Integers’ Representation. Binary Addition. Two's Complement.
Binary Arithmetic Binary arithmetic is essential in all digital computers and in many other types of digital systems. Addition, Subtraction, Multiplication,
Addition and Substraction
Fundamentals of Data Representation
Digital Logic & Design Lecture 02.
Unit 18: Computational Thinking
How are negative and rational numbers represented on the computer?
CPS120: Introduction to Computer Science
ECE 331 – Digital System Design
23/04/2019 Data Representation Conversion.
COMS 361 Computer Organization
靜夜思 床前明月光, 疑是地上霜。 舉頭望明月, 低頭思故鄉。 ~ 李白 李商隱.
Two’s Complement & Binary Arithmetic
Presentation transcript:

07/12/ Data Representation Two’s Complement & Binary Arithmetic

207/12/2015 Learning Objectives: Describe and use two's complement and sign and magnitude to represent positive and negative integers. Perform integer binary arithmetic: addition and subtraction.

307/12/2015 Representing Negative Numbers - Sign & Magnitude As there is no third symbol available to store a negative symbol explicitly we must use a bit to show if a number is negative or not. We name this bit the ‘Sign Bit’ We name this bit the ‘Sign Bit’ We use the leftmost bit. We use the leftmost bit. If the ‘Sign Bit’ is 1 then the number is negative, if it is 0 then it is positive. If the ‘Sign Bit’ is 1 then the number is negative, if it is 0 then it is positive.

407/12/2015 Representing Negative Numbers - Sign & Magnitude At first glance it may appear to be simple from this point, for example: 3 = = so -3 = so -3 = Sign Bits

507/12/2015 Binary – Decimal Spreadsheet Converter 2 Binary – Decimal Spreadsheet Converter 2 Try using it to ‘play’ with sign and magnitude binary numbers.

607/12/2015 Binary Arithmetic Rules = = = = 0 (carry 1) = 1 (carry 1)

707/12/2015 Problems with Sign & Magnitude To correct this error: Addition and subtraction calculations give incorrect results: e.g = 0 e.g = 0but i.e. not i.e. not This is due to the fact that the sign bit does not have a place value. This is due to the fact that the sign bit does not have a place value. Rules to correct this error: Rules to correct this error: If the signs are the same, add the magnitudes as unsigned numbers and, if there is a “carry out”, use it as the MSB (last bit). If the signs differ, subtract the smaller magnitude from the larger, and keep the sign of the larger e.g.

807/12/2015 Problems with Sign & Magnitude Also note that this method allows two representations of 0: This will cause problems for a processor.

907/12/2015 Two’s Complement This is a better way to represent negative numbers. Imagine a km clock in a car set at kilometres. If the car goes forward one km the reading becomes If the car goes forward one km the reading becomes If the meter was turned back one km the reading would be km. If the meter was turned back one km the reading would be km. This could be interpreted as ‘-1’ km. This could be interpreted as ‘-1’ km.

1007/12/2015 Negative denary to binary Work out the binary number as if it were positive. Work out the binary number as if it were positive. From the left, flip all bits up to the last ‘1’, leave this and any other bits after that alone. From the left, flip all bits up to the last ‘1’, leave this and any other bits after that alone. Flip means change 0 to 1 or 1 to 0. Negative binary to denary Reverse of above Reverse of above Using Two’s Complement

1107/12/2015 Two’s Complement So: = = = = = = = = = = = = = = -3 Sign Bit

1207/12/2015 Binary – Decimal Spreadsheet Converter 2 Binary – Decimal Spreadsheet Converter 2 Try using it to ‘play’ with two’s complement binary numbers.

1307/12/ Work out the binary number as if it were positive. 5 = = From the left, flip all bits up to the last ‘1’, leave this and any other bits after that alone. -5 = Don’t flip the last 1. 1

1407/12/ From the left, flip all bits up to the last ‘1’, leave this and any other bits after that alone Work out the decimal number as if it were positive = = 5 Add the minus sign = -5

1507/12/2015 The MSB stays as a number, but is made negative. This means that the column headings are does not need to use the MSB, so it stays as = = ( ) = ( ) Fitting this in the columns gives Alternative way of using Two’s Complement

1607/12/2015 Two’s Complement Now addition and subtraction calculations give the correct results: = = = = = <- carries <- carries Notes: Notes: The last ‘carry’ of 1 (carry in and out of the Most Significant Bit – MSB) has to be ignored unless an overflow has occurred (see next slide). The arithmetic works here, as all the bits, including the sign bit, in this method have a place value. There is only one representation for zero = = = -128 (not 0 as in sign & magnitude) = -128 (not 0 as in sign & magnitude)

+102 = = = 219 but = <- carries The original numbers are positive but the answer is negative! There has been an overflow from the positive part of the byte to the negative. To solve this error: If an "overflow" occurs add an extra bit and use this as the new sign bit. An overflow in a two's complement sum has occurred if: The sum of two positive numbers gives a negative result. The sum of two negative numbers gives a positive result. e.g. For the example above: = 219 (which is correct). Two’s Complement Problem with Two’s Complement New Sign bit (-256) old sign bit = New Sign bit (-256) old sign bit = + 128

1807/12/2015 Two’s Complement Also note that: There is only one representation for zero. There is only one representation for zero.

1907/12/2015 Plenary A particular computer stores numbers as 8 bit, two’s complement, binary numbers and are two numbers stored in the computer Write down the decimal equivalent of Add the two binary values together and comment on your answer.

2007/12/2015 Plenary = +47 A positive and negative have been added together and the result is positive. Because the larger value was positive. There was carry in and out of MSB therefore ignore carry out, (result is correct).