Faculty of Computer Science © 2006 CMPUT 229 Representing Information Numbers, Numbers, and Numbers.

Slides:



Advertisements
Similar presentations
CMPUT Computer Organization and Architecture I
Advertisements

Faculty of Computer Science © 2006 CMPUT 229 Floating Point Representation Operating with Real Numbers.
Chapter 2 : Number System
Assembly Language and Computer Architecture Using C++ and Java
Signed Numbers.
Assembly Language and Computer Architecture Using C++ and Java
Chapter Chapter Goals Know the different types of numbers Describe positional notation.
1 CSE-221 Digital Logic Design (DLD) Lecture-1: Digital Systems & Number Systems.
DIGITAL SYSTEMS TCE1111 Representation and Arithmetic Operations with Signed Numbers Week 6 and 7 (Lecture 1 of 2)
S. Barua – CPSC 240 CHAPTER 2 BITS, DATA TYPES, & OPERATIONS Topics to be covered are 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.
Number System and Codes
Binary Numbers.
Codes and number systems Introduction to Computer Yung-Yu Chuang with slides by Nisan & Schocken ( ) and Harris & Harris (DDCA)
Number Systems Computer Science 210 Computer Organization.
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 :
© Janice Regan, CMPT 128, Jan CMPT 128: Introduction to Computing Science for Engineering Students Integer Data representation Addition and Multiplication.
Simple Data Type Representation and conversion of numbers
Data Representation – Binary Numbers
Computers Organization & Assembly Language
Click to edit Master title style Click to edit Master text styles –Second level Third level –Fourth level »Fifth level 1 Today’s Topics How information.
1 Modified from  Modified from 1998 Morgan Kaufmann Publishers Chapter Three: Arithmetic for Computers citation and following credit line is included:
#1 Lec # 2 Winter EECC341 - Shaaban Positional Number Systems A number system consists of an order set of symbols (digits) with relations.
Dale & Lewis Chapter 3 Data Representation. Data and computers Everything inside a computer is stored as patterns of 0s and 1s Numbers, text, audio, video,
CHAPTER 1 INTRODUCTION NUMBER SYSTEMS AND CONVERSION.
Introduction to Computer Engineering ECE/CS 252, Fall 2010 Prof. Mikko Lipasti Department of Electrical and Computer Engineering University of Wisconsin.
46 Number Systems Problem: Implement simple pocket calculator Need: Display, adders & subtractors, inputs Display: Seven segment displays Inputs: Switches.
Representation of Data Ma King Man. Reference Text Book: Volume 2 Notes: Chapter 19.
Lecture 4 Last Lecture –Positional Numbering Systems –Converting Between Bases Today’s Topics –Signed Integer Representation Signed magnitude One’s complement.
Engineering 1040: Mechanisms & Electric Circuits Spring 2014 Number Systems.
Chapter 2 Binary Values and Number Systems. 2 2 Natural Numbers Zero and any number obtained by repeatedly adding one to it. Examples: 100, 0, 45645,
Bits, Data Types, and Operations Slides based on set prepared by Gregory T. Byrd, North Carolina State University.
Computer Arithmetic and the Arithmetic Unit Lesson 2 - Ioan Despi.
Cosc 2150: Computer Organization Chapter 2 Part 1 Integers addition and subtraction.
Number systems, Operations, and Codes
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.
1 Representation of Data within the Computer Oct., 1999(Revised 2001 Oct)
Number Systems and Logic Prepared by Dr P Marais (Modified by D Burford)
Chapter 2 Number Systems: Decimal, Binary, and Hex.
EEL 3801C EEL 3801 Part I Computing Basics. EEL 3801C Data Representation Digital computers are binary in nature. They operate only on 0’s and 1’s. Everything.
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.
Number Systems & Operations
Kavita Bala CS 3410, Spring 2014 Computer Science Cornell University.
Lecture 2 Binary Arithmetic Topics Terminology Fractions Base-r to decimal Unsigned Integers Signed magnitude Two’s complement August 26, 2003 CSCE 211.
Digital Fundamentals Tenth Edition Floyd Chapter 2 © 2008 Pearson Education.
CS1Q Computer Systems Lecture 2 Simon Gay. Lecture 2CS1Q Computer Systems - Simon Gay2 Binary Numbers We’ll look at some details of the representation.
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.
Bits, Data types, and Operations: Chapter 2 COMP 2610 Dr. James Money COMP
School of Computer and Communication Engineering, UniMAP Mohd ridzuan mohd nor DKT 122/3 - DIGITAL SYSTEM I Chapter.
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.
Introduction To Number Systems Binary System M. AL-Towaileb1.
CMPUT Computer Organization and Architecture I1 CMPUT229 - Fall 2002 Topic1: Numbers, Numbers, and Numbers José Nelson Amaral.
Negative Integers Unsigned binary representation can not be used to represent negative numbers. With paper and pencil arithmetic, a number is made negative.
©2010 Cengage Learning SLIDES FOR CHAPTER 1 INTRODUCTION NUMBER SYSTEMS AND CONVERSION Click the mouse to move to the next page. Use the ESC key to exit.
Lecture 2: 8/29/2002CS149D Fall CS149D Elements of Computer Science Ayman Abdel-Hamid Department of Computer Science Old Dominion University Lecture.
Bits, Data types, and Operations: Chapter 2 COMP 2610 Dr. James Money COMP
Lecture No. 4 Computer Logic Design. Negative Number Representation 3 Options –Sign-magnitude –One’s Complement –Two’s Complement  used in computers.
Number Systems. The position of each digit in a weighted number system is assigned a weight based on the base or radix of the system. The radix of decimal.
Binary Values. Numbers Natural Numbers Zero and any number obtained by repeatedly adding one to it. Examples: 100, 0, 45645, 32 Negative Numbers.
COSC2410: LAB 2 BINARY ARITHMETIC SIGNED NUMBERS FLOATING POINT REPRESENTATION BOOLEAN ALGEBRA 1.
Dr. ClincyLecture 2 Slide 1 CS Chapter 2 (1 of 5) Dr. Clincy Professor of CS Note: Do not study chapter 2’s appendix (the topics will be covered.
Cosc 2150: Computer Organization
3.1 Denary, Binary and Hexadecimal Number Systems
CSE 102 Introduction to Computer Engineering
Number Systems.
University of Gujrat Department of Computer Science
Data Representation in Computer Systems
CSC 220: Computer Organization Signed Number Representation
COMS 161 Introduction to Computing
靜夜思 床前明月光, 疑是地上霜。 舉頭望明月, 低頭思故鄉。 ~ 李白 李商隱.
Presentation transcript:

Faculty of Computer Science © 2006 CMPUT 229 Representing Information Numbers, Numbers, and Numbers

© 2006 Department of Computing Science CMPUT 229 Slide’s source Yale N. Patt and Sanjay J. Patel, Introduction to Computing Systems: From bits & gates to C & Beyond, McGrawHill Press, 2001, Chapter2.

© 2006 Department of Computing Science CMPUT 229 Positional Number System

© 2006 Department of Computing Science CMPUT 229 Positional Number System          19   

© 2006 Department of Computing Science CMPUT 229 Positional Number System             The same positional system works with different basis:

© 2006 Department of Computing Science CMPUT 229 Binary System             In computers we are mostly interested on bases 2, 8, and

© 2006 Department of Computing Science CMPUT 229 Signed Integers –Problem: given 2 k distinct patterns of bits, each pattern with k bits, assign integers to the patterns in such a way that: The numbers are spread in an interval around zero without gaps. Roughly half of the patterns represent positive numbers, and half represent negative numbers. When using standard binary addition, given an integer n, the following property should hold: pattern(n+1) = pattern(n) + pattern(1)

© 2006 Department of Computing Science CMPUT 229 Sign-Magnitude Representation In a sign-magnitude representation we use the first bit of the pattern to indicate if it is a positive or a negative number.

© 2006 Department of Computing Science CMPUT 229 Sign-Magnitude Represetation What do we do with the pattern 1000?

© 2006 Department of Computing Science CMPUT 229 Sign-Magnitude Representation Having two patterns to represent 0 is wasteful. The sign-magnitude representation has the advantage that it is easy to read the value from the pattern. But does it have the binary arithmetic property? For instance, what is the result of pattern(-1) + pattern(1)? 1001 pattern(-1) pattern(1) ?? PattPatel, pp. 20

© 2006 Department of Computing Science CMPUT 229 Sign-Magnitude Representation Having two patterns to represent 0 is wasteful. The sign-magnitude representation has the advantage that it is easy to read the value from the pattern. But does it have the arithmetic property? For instance, what is the result of pattern(-1) + pattern(1)? 1001 pattern(-1) pattern(1) 1010 = ?? PattPatel, pp. 20

© 2006 Department of Computing Science CMPUT 229 Sign-Magnitude Representation Having two patterns to represent 0 is wasteful. The sign-magnitude representation has the advantage that it is easy to read the value from the pattern. But does it have the arithmetic property? For instance, what is the result of pattern(-1) + pattern(1)? 1001 pattern(-1) pattern(1) 1010 = pattern(-2) PattPatel, pp. 20

© 2006 Department of Computing Science CMPUT 229 1’s-Complement Representation A negative number is represented by “flipping” all the bits of a positive number. We still have two patterns for 0. It is still easy to read a value from a given pattern. How about the arithmetic property? Suggestion: try the following = ?? = ?? = ?? PattPatel, pp. 20

© 2006 Department of Computing Science CMPUT 229 2’s-Complement Representation A single pattern for pattern(-1) pattern(1) 0000 = pattern(0) It holds the arithmetic property. But the reading of a negative pattern is not trivial. PattPatel, pp. 20

© 2006 Department of Computing Science CMPUT 229 Binary to Decimal Conversion Problem: Given an 8-bit 2’s complement binary number: a 7 a 6 a 5 a 4 a 3 a 2 a 1 a 0 find its corresponding decimal value. Because the binary representation has 8 bits, the decimal value must be in the [-2 7 ; +(2 7 -1)] =[-128;+127] interval. PattPatel, pp. 23

© 2006 Department of Computing Science CMPUT 229 if (negative = true) then Binary to Decimal Conversion a 7 a 6 a 5 a 4 a 3 a 2 a 1 a 0 Solution: negative  false if (a 7 = 1) then negative  true flip all bits; compute magnitude using: PattPatel, pp. 24

© 2006 Department of Computing Science CMPUT 229 Binary to Decimal Conversion (Examples) Convert the 2’s complement integer to its decimal integer value. 1. a 7 is 1, thus we make a note that this is a negative number and invert all the bits, obtaining: We compute the magnitude: 3. Now we remember that it was a negative number, thus: PattPatel, pp. 24

© 2006 Department of Computing Science CMPUT 229 Decimal to Binary Convertion We will start with an example. What is the binary representation of ? Our problem is to find the values of each a i Because 105 is odd, we know that a 0 = 1 Thus we can subtract 1 from both sides to obtain: PattPatel, pp. 24

© 2006 Department of Computing Science CMPUT 229 Decimal to Binary Convertion (cont.) Now we can divide both sides by 2 Because 52 is even, we know that a 1 = 0 a 2 = 0 a 3 = 1 PattPatel, pp. 24

© 2006 Department of Computing Science CMPUT 229 Decimal to Binary Convertion (cont.) a 4 = 0a 5 = 1a 6 = 1 Thus we got: a 1 = 0a 4 = 0a 5 = 1a 6 = 1a 2 = 0a 3 = 1a 0 = = PattPatel, pp. 25

© 2006 Department of Computing Science CMPUT 229 Decimal to Binary Conversion (Another Method) We can also use repeated long division: 105/2 = 52 remainder 1 52/2 = 26 remainder 0 26/2 = 13 remainder 0 13/2 = 6 remainder 1 6/2 = 3 remainder 0 3/2 = 1 remainder 1 1/2 = 0 remainder 1

© 2006 Department of Computing Science CMPUT 229 Decimal to Binary Conversion (Another Method) We can also use repeated long division: 105/2 = 52 remainder 1 52/2 = 26 remainder 0 26/2 = 13 remainder 0 13/2 = 6 remainder 1 6/2 = 3 remainder 0 3/2 = 1 remainder 1 1/2 = 0 remainder 1 rightmost digit =

© 2006 Department of Computing Science CMPUT 229 Decimal to Binary Conversion (Negative Numbers) What is the binary representation of in 8 bits? We know from the previous slide that: = To obtain the binary representation of a negative number we must flip all the bits of the positive representation and add 1: Thus: = PattPatel, pp

© 2006 Department of Computing Science CMPUT 229 Hexadecimal Numbers (base 16) If the number $FACE represents a 2’s complement binary number, what is its decimal value? In the 68K assembler, by convention, the character $ is printed in front of an hexadecimal number to indicate base 16. First we need to look up the binary representation of F, which is Therefore $FACE is a negative number, and we have to flip all the bits. PattPatel, pp

© 2006 Department of Computing Science CMPUT 229 Hexadecimal Numbers (base 16) It is best to write down the binary representation of the number first: $FACE = Now we flip all the bits and add 1: = $0532 Then we convert 0x0532 from base 16 to base 10: $0532 = 0     16 0 =    1 = = $FACE = PattPatel, pp

© 2006 Department of Computing Science CMPUT 229 Binary Arithmetic Decimal Binary Decimal Binary = = PattPatel, pp. 25

© 2006 Department of Computing Science CMPUT 229 Overflow What happens if we try to add +9 with +11 in a 5-bit 2-complement representation? Decimal Binary = -12 ? The result is too large to represent in 5 digits, i.e. it is larger than = When the result is too large for the representation we say that the result has OVERFLOWed the capacity of the representation. PattPatel, pp. 27

© 2006 Department of Computing Science CMPUT 229 Overflow Detection What happens if we try to add +9 with +11 in a 5-bit 2-complement representation? Decimal Binary = -12 ? We can easily detect the overflow by detecting that the addition of two positive numbers resulted in a negative result. PattPatel, pp. 28

© 2006 Department of Computing Science CMPUT 229 Overflow (another example) Could overflow happen when we add two negative numbers? Decimal Binary = +14 ? Again we can detect overflow by detecting that we added two negative numbers and got a positive result. Could we get overflow when adding a positive and a negative number? PattPatel, pp. 28

© 2006 Department of Computing Science CMPUT 229 Sign-extension What is the 8-bit representation of ? What is the 16-bit representation of ? What is the 8-bit representation of ? What is the 8-bit representation of ? PattPatel, pp. 27

© 2006 Department of Computing Science CMPUT 229 Sign-extension What is the 8-bit representation of ? What is the 16-bit representation of ? What is the 8-bit representation of ? What is the 8-bit representation of ? To sign-extend a number to a larger representation, all we have to do is to replicate the sign bit until we obtain the new length. PattPatel, pp. 27

© 2006 Department of Computing Science CMPUT 229 Some Useful Numbers to Remember 2 0 = 1 10 = $ = 2 10 = $ = 4 10 = $ = 8 10 = $ = = $ = = $ = = $ = = $ = = $ = = $ = = = $0400 = 1K 2 20 = 2 10 × 2 10 = × = = $ = 1M 2 30 = 2 10 × 2 10 × 2 10 = 1 G 2 40 = 2 10 × 2 10 × 2 10 × 2 10 = 1 T

© 2006 Department of Computing Science CMPUT 229 Data and Addresses “She is 104.” “I am staying at 104.” “It costs 104.” “There is 104.” “My office is 104.” “Stop in front of 104.” “My house is 104.” In each case, how do we know what 104 is? From the context in which it is used! The same is true for data and addresses. The same number is data on one instance and address on another. “Write 100 at $0780.” “Write 100 at 100.”

© 2006 Department of Computing Science CMPUT 229 Representing Fractions In base 10 we know that: = / = /10 3 Fractions are represented in a similar fashion in base 2: = / = / = and 2 5 = 32, thus = /32 10 = Clements, pp. 152

© 2006 Department of Computing Science CMPUT 229 Fractions: Binary to Decimal Another way to convert a binary fraction into a decimal value is as follows: = 1      2 -5 = 1      = =

© 2006 Department of Computing Science CMPUT 229 Fractions: Decimal to Binary The following method works to convert decimal factions to binary: = ??  2 =  2 =  2 =  2 =  2 Done! =

© 2006 Department of Computing Science CMPUT 229