2’s Complement Another system that lets us represent negative numbers

Slides:



Advertisements
Similar presentations
Fixed Point Numbers The binary integer arithmetic you are used to is known by the more general term of Fixed Point arithmetic. Fixed Point means that we.
Advertisements

HEXADECIMAL NUMBERS Code
Arithmetic & Logic Unit Does the calculations Everything else in the computer is there to service this unit Handles integers May handle floating point.
Computer ArchitectureFall 2008 © August 25, CS 447 – Computer Architecture Lecture 3 Computer Arithmetic (1)
CSE 378 Floating-point1 How to represent real numbers In decimal scientific notation –sign –fraction –base (i.e., 10) to some power Most of the time, usual.
Exercise 2.5 If each number is represented with 5 bits, 7 = in all three systems -7 = (1's complement) = (signed magnitude) = (2's.
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.
INTEGERS: adding, subtracting, multiplying, and dividing
3. Representing Integer Data
NEGATIVE BINARY NUMBER – Digital Circuit 1 Choopan Rattanapoka.
Binary Representation - Shortcuts n Negation x + x = 1111…1111 two = -1 (in 2’s complement) Therefore, -x = x + 1 n Sign Extension o Positive numbers :
Binary numbers and arithmetic. ADDITION Addition (decimal)
Computer Organization & Programming Chapter2 Number Representation and Logic Operations.
Binary Real Numbers. Introduction Computers must be able to represent real numbers (numbers w/ fractions) Two different ways:  Fixed-point  Floating-point.
Conversion Between Lengths Positive number pack with leading zeros +18 = = Negative numbers pack with leading ones -18 =
Number Systems Part 2 Numerical Overflow Right and Left Shifts Storage Methods Subtraction Ranges.
Complement Numbers. Outline  Negative Numbers Representation  Sign-and-magnitude  1s Complement  2s Complement  Comparison of Sign-and-Magnitude.
+ CS 325: CS Hardware and Software Organization and Architecture Integers and Arithmetic Part 2.
9.4 FLOATING-POINT REPRESENTATION
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.
Number Systems. Today Decimal Hexadecimal Binary –Unsigned Binary –1’s Complement Binary –2’s Complement Binary.
46 Number Systems Problem: Implement simple pocket calculator Need: Display, adders & subtractors, inputs Display: Seven segment displays Inputs: Switches.
Positional Number Systems
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.
Lesson 4-7 Example Example 1 Find 4.32 × Multiply the factors, ignoring the decimal points for now. 432 × 6 = 2592.
07/12/ Data Representation Two’s Complement & Binary Arithmetic.
Addition and Substraction
69 Decimal (Base 10) Numbers n Positional system - each digit position has a value n 2534 = 2*1, * *10 + 4*1 n Alternate view: Digit position.
1 4. Computer Maths and Logic 4.1 Number Systems.
Introduction * Binary numbers are represented with a separate sign bit along with the magnitude. * For example, in an 8-bit binary number, the MSB is.
2's Complement Arithmetic
1 Digital Logic Design Lecture 2 More Number Systems/Complements.
Adding and Subtracting Decimals. Essential Question: How do I add and subtract decimals? Always line up decimals Add and subtract like you always do Bring.
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.
Numerical formats What’s the main idea? Want to represent numbers (eg: 45, -12, ) using only bits. We’ve already seen (or you can read in the book)
ECEN 248: INTRODUCTION TO DIGITAL SYSTEMS DESIGN Lecture 8 Dr. Shi Dept. of Electrical and Computer Engineering.
09/03/20161 Information Representation Two’s Complement & Binary Arithmetic.
Bits, Data types, and Operations: Chapter 2 COMP 2610 Dr. James Money COMP
Copyright©amberpasillas – (- 0.34) 4 Step 2: Line up the decimals Step 3: If needed, put zeros in as place holders Step 4: Add decimals.
{ 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.
COSC2410: LAB 2 BINARY ARITHMETIC SIGNED NUMBERS FLOATING POINT REPRESENTATION BOOLEAN ALGEBRA 1.
Binary Addition The simplest arithmetic operation in binary is addition. Adding two single-digit binary numbers is relatively simple, using a form of carrying:
11001 / 101, / ) Perform subtraction on the given unsigned binary numbers using the 2's complement of the subtrahend. Where the result.
CPE 201 Digital Design Lecture 3: Digital Systems & Binary Numbers (3)
Addition and Subtraction
Negative Binary Numbers
11001 / 101 , / ) Perform subtraction on the given unsigned binary numbers using the 2's complement of the subtrahend. Where the.
Computer Science 210 Computer Organization
CSCI206 - Computer Organization & Programming
Addition of Signed Numbers
Lecture 2 Topics Binary Arithmetic (Unsigned binary operands)
Negative Binary Numbers
Addition and Substraction
Binary Addition & Subtraction
Computer Organization and ASSEMBLY LANGUAGE
Scientific Notation.
1.6) Storing Integer:.
Two’s Complement Shortcut
Unit 18: Computational Thinking
Adding and Subtracting Decimals
Binary “There are 10 types of people in the world: Those who understand binary, and those who don't.”
Decimal and binary representation systems
ECE 171 Digital Circuits Chapter 2 Binary Arithmetic
Adding and Subtracting Decimals
Adding and Subtracting Decimals
Adding and Subtracting Decimals
COMS 361 Computer Organization
Two’s Complement & Binary Arithmetic
Presentation transcript:

2’s Complement Another system that lets us represent negative numbers MSB is STILL the sign bit, but there is no negative zero Negative numbers count backwards and wrap around Calculating 2’s complement (Pos  Neg) Flip the bits ( 01 and 10 ) Add 1

Example ( Pos  Neg ) 110  -110 00012  11112 Flip bits: 1110 110  -110 00012  11112 Flip bits: 1110 Add 1: 1110 +0001 1111

Another Example ( Pos  Neg ) 2510  -2510 000110012  11100111 2 Flip bits: 11100110 Add 1: 11100110 +00000001 11100111

Your Turn Assuming an 8-bit restriction, what is -2110 in 2’s complement? Flip bits Add 1 Answer: 111010112

Your Turn Assuming an 8-bit restriction, what is -3010 in 2’s complement? Flip bits Add 1 Answer: 111000102

Example ( Neg Pos ) -410  410 11002  01002 Flip bits: 0011 -410  410 11002  01002 Flip bits: 0011 Add 1: 0011 +0001 0100

Another Example ( Neg  Pos ) -2910  2910 111000112  000111012 Flip bits: 00011100 Add 1: 00011100 +00000001 00011101

Your Turn Assuming 2’s complement, what is the decimal value of 111110012? Flip bits Add 1 Answer: -710

Your Turn Assuming 2’s complement, what is the decimal value of 111010102? Flip bits Add 1 Answer: 22

2’s Complement Chart Binary Decimal 0111 7 0110 6 0101 5 0100 4 0011 3 0010 2 0001 1 0000 1111 -1 1110 -2 1101 -3 1100 -4 1011 -5 1010 -6 1001 -7 1000 -8 Binary Decimal 00000111 7 00000110 6 00000101 5 00000100 4 00000011 3 00000010 2 00000001 1 00000000 11111111 -1 11111110 -2 11111101 -3 11111100 -4 11111011 -5 11111010 -6 11111001 -7 11111000 -8

SHORTCUT! Find the 1 on the farthest right Flip all the bits to the left of the 1 (DO NOT FLIP THE 1) Example: 4210  -4210 001010102  110101102

Awesomeness of 2’s Complement No more negative zero Lower minimum value: -(2N-1) So what’s the big deal? Everything is addition No need for special hardware to do subtraction

2’s Complement Addition Just like normal positive binary addition You MUST restrict the number of bits IGNORE any overflow bits maintain bit-size restriction

Positive Addition Example 1210 + 410 = 1610 Assuming 2’s complement 000010102 1210 +000000102 + 410 000011002 1610

Negative Addition Example -1210 + -410 = -1610 111101002 -1210 +111111002 + -410 111100002 -1610 NOTE: We ignored the last overflow bit on the left!

Your Turn Show the binary addition of -14 + -3 = -17

Subtraction Example 1610 – 410 = 1610 + -410 = 1210 000100002 +111111002 000011002 NOTE: We ignored the last overflow bit on the left!

Your Turn Show the binary subtraction of 23 – 10 = 13

Overflow / Underflow Problem Addition and bit-size restriction allow for possible overflow / underflow Overflow – when the addition of two binary numbers yields a result that is greater than the maximum possible value Underflow – when the addition/subtraction of two binary numbers yields a result that is less than the minimum possible value

Overflow Example Assume 4-bit restriction and 2’s complement Maximum possible value: 24-1 – 1 = 7 610 + 310 = 910 01102 610 +00112 +310 10012 -710  not good!

Underflow Example Assume 4-bit restriction and 2’s complement Minimum possible value: -(24-1) = -8 -510 + -510 = -1010 10112 -510 +10112 +-510 01102 610  not good!