Numerical formats What’s the main idea? Want to represent numbers (eg: 45, -12, 2.4556) using only bits. We’ve already seen (or you can read in the book)

Slides:



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

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 Numerical Representations On The Computer: Negative And Rational Numbers How are negative and rational numbers represented on the computer? How.
CS 151 Digital Systems Design Lecture 3 More Number Systems.
1 Binary Arithmetic, Subtraction The rules for binary arithmetic are: = 0, carry = = 1, carry = = 1, carry = = 0, carry =
ENGIN112 L3: More Number Systems September 8, 2003 ENGIN 112 Intro to Electrical and Computer Engineering Lecture 3 More Number Systems.
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.
Data Representation – Chapter 3 Sections 3-2, 3-3, 3-4.
Binary Arithmetic Math For Computers.
Chapter 3 Data Representation part2 Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2010.
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 Addition Addition Rules: = = = = = carry 1 1 carry 1 Example 1: Example 2:
ECE 2110: Introduction to Digital Systems Signed Number Conversions.
Computer Organization & Programming Chapter2 Number Representation and Logic Operations.
© Janice Regan, CMPT 128, Jan CMPT 128: Introduction to Computing Science for Engineering Students Integer Data representation Addition and Multiplication.
Lecture 5.
CMPE 325 Computer Architecture II Cem Ergün Eastern Mediterranean University Integer Representation and the ALU.
Number Systems Part 2 Numerical Overflow Right and Left Shifts Storage Methods Subtraction Ranges.
IT253: Computer Organization
CS Binary Representation of Information Detecting Voltage Levels Why not 10 levels? Would be unreliable Not enough difference between states On/Off.
CPS120: Introduction to Computer Science Computer Math: Signed Numbers.
Computer Math. The Decimal System How do we represent “One Hundred and Twenty Five”? How do we represent “One Hundred and Twenty Five”? Simple: 125 !!!
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.
Number Representation
Number Systems Binary to Decimal Octal to Decimal Hexadecimal to Decimal Binary to Octal Binary to Hexadecimal Two’s Complement.
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.
Sep 29, 2004Subtraction (lvk)1 Negative Numbers and Subtraction The adders we designed can add only non-negative numbers – If we can represent negative.
08 ARTH Page 1 ECEn/CS 224 Number Representation and Binary Arithmetic.
Data Representation in Computer Systems. 2 Signed Integer Representation The conversions we have so far presented have involved only positive numbers.
07/12/ Data Representation Two’s Complement & Binary Arithmetic.
Addition and Substraction
Digital Logic Lecture 3 Binary Arithmetic By Zyad Dwekat The Hashemite University Computer Engineering Department.
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=
CS1Q Computer Systems Lecture 2 Simon Gay. Lecture 2CS1Q Computer Systems - Simon Gay2 Binary Numbers We’ll look at some details of the representation.
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.
1 Digital Logic Design Lecture 2 More Number Systems/Complements.
James Tam Numerical Representations On The Computer: Negative And Rational Numbers How are negative and rational numbers represented on the computer? How.
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.
09/03/20161 Information Representation Two’s Complement & Binary Arithmetic.
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.”
Computer Engineering page 1 Integer arithmetic Depends what you mean by “integer”. Assume at 3-bit string. –Then we define: zero = 000 one = 001 Use zero,
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:
Lecture 4: Digital Systems & Binary Numbers (4)
Representing Positive and Negative Numbers
Negative Number Sign-Magnitude: left-most bit as the sign bit –16 bits –Example: 4-bit numbers is given by is given by ’s complement:
Negative Numbers and Subtraction
Negative Binary Numbers
Negative Binary Numbers
Addition and Substraction
Binary Addition & Subtraction
Wakerly Section 2.4 and further
Data Representation in Computer Systems
Subtraction The arithmetic we did so far was limited to unsigned (positive) integers. Today we’ll consider negative numbers and subtraction. The main problem.
Data Representation – Chapter 3
EEL 3705 / 3705L Digital Logic Design
Unit 18: Computational Thinking
How are negative and rational numbers represented on the computer?
ECE 331 – Digital System Design
GCSE COMPUTER SCIENCE Topic 3 - Data 3.2 Signed Integers.
Two’s Complement & Binary Arithmetic
Today Binary addition Representing negative numbers 2.
Presentation transcript:

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) how to convert all these numbers to binary. We can then use one bit for each binary digit. Doesn’t that solve the problem??? Well, not quite: we still need a way to take into account the sign, and the decimal point.

Adding signs Let’s now add the concept of signs Simplest way: Add a sign bit. This is called sign magnitude. –Example: 93 is Then -93 is: –Advantage: Very easy to take the negation of a number. –Disadvantage: hard to do additions. Need something better!

2’s complement The motivation here is to make adding signed numbers VERY easy. Notice the following: if you ignore errors of “off by 100”, then 0 and 100, look very similar Positive Negative Positive

2’s complement (cont’d) So, a positive number I is represented by I itself. A negative number -I is represented by I. Example: = ?? Positive Negative Positive

2’s complement (cont’d) Another example: (-10) + (-10) = ?? Positive Negative Positive 200 Negative

2’s complement (cont’d) Wow, this works! We can add numbers without thinking about their sign! Let’s do this in binary. Example with 4 bits. Instead of using decimal 100 as 0 mark, we use binary So -I is represented by I. Everything is the same just that we do things in binary. Shortcut for computing 2’s complement. – I = ( ) - I = ( I) + 1 –What does A mean? It’s the same as inverting... –So, to take 2’s complement: invert bits and add 1.

2’s complement (cont’d) Example in 4 bits: –How do we represent -6? –6 in binary is 0110 –Invert: 1001 –Add 1: 1010 –Note that if we do the same again, we get the original bit stream. –Also note that the msb conveniently tells us the sign of the number.

2’s complement (cont’d) Example in 4 bits:

2’s complement (cont’d) Just one thing: Recall the example with decimals. What happens if we add 40 and 40? We get 80, but we interpret 80 as -20… This is called overflow. In 2’s complement addition, overflow occurs if both operands are positive but the result is negative, or if both operands are negative and the result is positive. In 2’s complement subtraction, overflow occurs if a positive number is subtracted from a negative number and the result is positive, or if a negative number is subtracted from a positive number and the result is negative. Don’t confuse carry and overflow...

1’s complement (cont’d) Problem with 2’s complement: hard to find the negation of a number because it involves “adding 1” This leads to 1’s complement. In 1’s complement, instead of subtracting from 100, you subtract from 99. This means that in binary, you only need to invert the bits! The price to pay is that when we pass the 100 mark, we’ll be off by 1 (eg: leads to = 119. But we want 120!). So, every time you pass the 100 mark, you need to add an extra 1.

1’s complement (cont’d) Example in 4 bits: