CMPUT Computer Organization and Architecture I

Slides:



Advertisements
Similar presentations
ICS312 Set 2 Representation of Numbers and Characters.
Advertisements

Representing Numbers: Integers
Lecture - 2 Number systems and computer data formats
2-1 Chapter 2 - Data Representation Computer Architecture and Organization by M. Murdocca and V. Heuring © 2007 M. Murdocca and V. Heuring Computer Architecture.
Chapter 2: Data Representation
Principles of Computer Architecture Miles Murdocca and Vincent Heuring Chapter 2: Data Representation.
Chapter 2 : Number System
Floating Point Numbers
Digital Fundamentals Floyd Chapter 2 Tenth Edition
Faculty of Computer Science © 2006 CMPUT 229 Representing Information Numbers, Numbers, and Numbers.
Signed Numbers.
2-1 Computer Organization Part Fixed Point Numbers Using only two digits of precision for signed base 10 numbers, the range (interval between lowest.
Floating Point Numbers
Data Representation in Computers
S. Barua – CPSC 240 CHAPTER 2 BITS, DATA TYPES, & OPERATIONS Topics to be covered are Number systems.
Number Systems Computer Science 210 Computer Organization.
1.6 Signed Binary Numbers.
Dr. Bernard Chen Ph.D. University of Central Arkansas
© 2009 Pearson Education, Upper Saddle River, NJ All Rights ReservedFloyd, Digital Fundamentals, 10 th ed Digital Fundamentals Tenth Edition Floyd.
Simple Data Type Representation and conversion of numbers
Data Representation – Binary Numbers
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.
2-1 Chapter 2 - Data Representation Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Chapter Contents.
NUMBER REPRESENTATION CHAPTER 3 – part 3. ONE’S COMPLEMENT REPRESENTATION CHAPTER 3 – part 3.
Computer Science 111 Fundamentals of Programming I Number Systems.
IT253: Computer Organization
Fundamental of Computer Architecture By Panyayot Chaikan November 01, 2003.
Data Representation - Part I. Representing Numbers Choosing an appropriate representation is a critical decision a computer designer has to make The chosen.
2-1 Chapter 2 - Data Representation Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Principles of Computer.
Binary Arithmetic & Data representation
Data Representation and Computer Arithmetic
COMPSCI 210 Semester Tutorial 1
ICS312 Set 1 Representation of Numbers and Characters.
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 !!!
Data Representation Dr. Ahmed El-Bialy Dr. Sahar Fawzy.
©Brooks/Cole, 2003 Chapter 3 Number Representation.
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)
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.
Data Representation, Number Systems and Base Conversions
AEEE2031 Data Representation and Numbering Systems.
CDP ECE Spring 2000 ECE 291 Spring 2000 Lecture 2: Number Systems & x86 Instructions Constantine D. Polychronopoulos Professor, ECE Office: 463.
SAK Chapter 21 Chapter 2 : Number System 2.1 Decimal, Binary, Octal and Hexadecimal Numbers 2.2 Relation between binary number system with other.
Number Systems Denary Base 10 Binary Base 2 Hexadecimal Base 16
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.
Data Representation.
CMPUT Computer Organization and Architecture I1 CMPUT229 - Fall 2002 Topic1: Numbers, Numbers, and Numbers José Nelson Amaral.
©Brooks/Cole, 2003 Chapter 3 Number Representation.
Chapter 1 Representing Data in a Computer. 1.1 Binary and Hexadecimal Numbers.
CS 125 Lecture 3 Martin van Bommel. Overflow In 16-bit two’s complement, what happens if we add =
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.
COSC2410: LAB 2 BINARY ARITHMETIC SIGNED NUMBERS FLOATING POINT REPRESENTATION BOOLEAN ALGEBRA 1.
3.1 Denary, Binary and Hexadecimal Number Systems We use the denary (base 10) number system in our daily life for counting and calculation. Computers use.
1 CE 454 Computer Architecture Lecture 4 Ahmed Ezzat The Digital Logic, Ch-3.1.
CS2100 Computer Organisation
Some basic concepts underlying computer archi­tecture
Compsci 210 Tutorial Two CompSci Semester Two 2016.
NUMBER SYSTEMS.
3.1 Denary, Binary and Hexadecimal Number Systems
Data Representation Binary Numbers Binary Addition
Number Systems.
CS1010 Programming Methodology
Data Structures Mohammed Thajeel To the second year students
Number Representation
Storing Negative Integers
OBJECTIVES After reading this chapter, the reader should be able to :
靜夜思 床前明月光, 疑是地上霜。 舉頭望明月, 低頭思故鄉。 ~ 李白 李商隱.
Presentation transcript:

CMPUT 229 - Computer Organization and Architecture I 2. Number Systems Decimal Binary Addition Headecimal Two’s complement ASCII characters CMPUT 229 - Computer Organization and Architecture I

Positional Number System 329 923 3 2 9 9 2 3 9 2 3 9 2 3 329 923 CMPUT 229 - Computer Organization and Architecture I

CMPUT 229 - Computer Organization and Architecture I Decimal numbers 329 923 3102 + 2101 + 9100 9102 + 2101 + 3100 3100 + 210 + 91 9100 + 210 + 31 300 + 20 + 9 900 + 20 + 3 329 923 CMPUT 229 - Computer Organization and Architecture I

Positional Number System The same positional system works with different basis: 32913 92313 3132 + 2131 + 9130 9132 + 2131 + 3130 3169 + 213 + 91 9169 + 213 + 31 50710 + 2610 + 910 152110 + 2610 + 310 54210 155010 CMPUT 229 - Computer Organization and Architecture I

Binary System 1102 92316 122 + 121 + 020 9162 + 2161 + 3160 In computers we are mostly interested on bases 2, 8, and 16. 1102 92316 122 + 121 + 020 9162 + 2161 + 3160 14 + 12 + 01 9256 + 216 + 31 410 + 210 + 010 230410 + 3210 + 310 610 233910 CMPUT 229 - Computer Organization and Architecture I

CMPUT 229 - Computer Organization and Architecture I Signed Integers Problem: given 2k 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) CMPUT 229 - Computer Organization and Architecture I

Signed Magnitude In a signed magnitude representation we use the first bit of the pattern to indicate if it is a positive or a negative number.

Signed Magnitude What do we do with the pattern 1000?

Signed Magnitude Having two patterns to represent 0 is wasteful. The signed 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) + 0001 pattern(1) ?? PattPatel pp. 20

Signed Magnitude Having two patterns to represent 0 is wasteful. The signed 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) + 0001 pattern(1) 1010 = ?? PattPatel pp. 20

Signed Magnitude Having two patterns to represent 0 is wasteful. The signed 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) + 0001 pattern(1) 1010 = pattern(-2) PattPatel pp. 20

1’s Complement 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 folllowing -1 + 1 = ?? -0 + 1 = ?? 0 + 1 = ?? PattPatel pp. 20

CMPUT 229 - Computer Organization and Architecture I 2’s Complement a representation for negative numbers The leftmost bit is used to indicate +/- Positive number starts with 0, negative 1 A negative number is obtained by Convert the corresponding positive decimal number to a binary toggle all bits ( all 10 and all 0 1) Add 1 to the the binary obtained in the previous step CMPUT 229 - Computer Organization and Architecture I

2’s Complement A single pattern for 0. 1111 pattern(-1) It holds the arithmetic property. But the reading of a negative pattern is not trivial. PattPatel pp. 20

Binary to Decimal Conversion Problem: Given an 8-bit 2’s complement binary number: a7 a6 a5 a4 a3 a2 a1 a0 find its corresponding decimal value. Because the binary representation has 8 bits, the decimal value must be in the [-27; +(27-1)] =[-128;+127] interval. CMPUT 229 - Computer Organization and Architecture I PattPatel pp. 23

Binary to Decimal Conversion a7 a6 a5 a4 a3 a2 a1 a0 Solution: negative  false if (a7 = 1) then negative  true flip all bits; compute magnitude using: if (negative = true) then CMPUT 229 - Computer Organization and Architecture I PattPatel pp. 24

Binary to Decimal Conversion (Examples) Convert the 2’s complement integer 11000111 to its decimal integer value. 1. a7 is 1, thus we make a note that this is a negative number and invert all the bits, obtaining: 00111000 2. We compute the magnitude: 3. Now we remember that it was a negative number, thus: CMPUT 229 - Computer Organization and Architecture I PattPatel pp. 24

Decimal to Binary Convertion We will start with an example. What is the binary representation of 10510? Our problem is to find the values of each ai Because 105 is odd, we know that a0 = 1 Thus we can subtract 1 from both sides to obtain: CMPUT 229 - Computer Organization and Architecture I PattPatel pp. 24

Decimal to Binary Convertion (cont.) Now we can divide both sides by 2 Because 52 is even, we know that a1 = 0 a2 = 0 a3 = 1 CMPUT 229 - Computer Organization and Architecture I PattPatel pp. 24

Decimal to Binary Convertion (cont.) Thus we got: a1 = 0 a4 = 0 a5 = 1 a6 = 1 a2 = 0 a3 = 1 a0 = 1 10510 = 011010012 CMPUT 229 - Computer Organization and Architecture I PattPatel pp. 25

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 CMPUT 229 - Computer Organization and Architecture I

Decimal to Binary Conversion (Another Method) We can also use repeated long division: rightmost digit 105/2 = 52 remainder 1 52/2 = 26 remainder 0 26/2 = 13 remainder 0 13/2 = 6 remainder 1 10510 = 011010012 6/2 = 3 remainder 0 3/2 = 1 remainder 1 1/2 = 0 remainder 1 CMPUT 229 - Computer Organization and Architecture I

Decimal to Binary Conversion (Negative Numbers) What is the binary representation of -10510 in 8 bits? We know from the previous slide that: +10510 =011010012 To obtain the binary representation of a negative number we must flip all the bits of the positive representation and add 1: 10010110 + 00000001 10010111 Thus: -10510 =100101112 CMPUT 229 - Computer Organization and Architecture I PattPatel pp. 22-23

Hexadecimal Numbers (base 16) By convention, the characters 0x are printed in front of an hexadecimal number to indicate base 16. If the number 0xFACE represents a 2’s complement binary number, what is its decimal value? First we need to look up the binary representation of F, which is 1111. Therefore 0xFACE is a negative number, and we have to flip all the bits. CMPUT 229 - Computer Organization and Architecture I PattPatel pp. 26-27

Hexadecimal Numbers (base 16) It is best to write down the binary representation of the number first: 0xFACE = 1111 1010 1100 1110 Now we flip all the bits and add 1: 0000 0101 0011 0001 + 0000 0000 0000 0001 0000 0101 0011 0010 = 0x0532 Then we convert 0x0532 from base 16 to base 10: 0x0532 = 0163 + 5162 + 3161 + 2160 = 0 + 5256 + 316 + 21 = 1280 + 48 + 2 = 133010 0xFACE = -133010 CMPUT 229 - Computer Organization and Architecture I PattPatel pp. 26-27

CMPUT 229 - Computer Organization and Architecture I Binary Arithmetic Decimal 19 + 3 22 Binary 010011 + 000011 010110 Binary 001110 + 110111 000101 Decimal 14 - 9 5 910 = 0010012 -910 = 1101112 CMPUT 229 - Computer Organization and Architecture I PattPatel pp. 25

Overflow What happens if we try to add +9 with +11 in a 5-bit 2-complement representation? Decimal 9 + 11 20 Binary 01001 + 01011 10100 = -12 ? The result is too large to represent in 5 digits, i.e. it is larger than 01111 = +1510. When the result is too large for the representation we say that the result has OVERFLOWed the capacity of the representation? CMPUT 229 - Computer Organization and Architecture I PattPatel pp. 27

CMPUT 229 - Computer Organization and Architecture I Overflow Detection What happens if we try to add +9 with +11 in a 5-bit 2-complement representation? Decimal 9 + 11 20 Binary 01001 + 01011 10100 = -12 ? We can easily detect the overflow by detecting that the addition of two positive numbers resulted in a negative result. CMPUT 229 - Computer Organization and Architecture I PattPatel pp. 28

Overflow (another example) Could overflow happen when we add two negative numbers? Decimal - 12 + -6 -18 Binary 10100 + 11010 01110 = +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? CMPUT 229 - Computer Organization and Architecture I PattPatel pp. 28

Sign-extension What is the 8-bit representation of +510? 0000 0101 0000 0000 0000 0101 What is the 8-bit representation of -510? 1111 1011 What is the 8-bit representation of -510? 1111 1111 1111 1011 CMPUT 229 - Computer Organization and Architecture I PattPatel pp. 27

Sign-extension What is the 8-bit representation of +510? 0000 0101 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. What is the 16-bit representation of +510? 0000 0000 0000 0101 What is the 8-bit representation of -510? 1111 1011 What is the 8-bit representation of -510? 1111 1111 1111 1011 CMPUT 229 - Computer Organization and Architecture I PattPatel pp. 27

CMPUT 229 - Computer Organization and Architecture I Storing characters ASCII (American Standard Code for Information Interchange) One byte UTF-8 (8-bit Unicode Transformation Format) One to four bytes Coincides with ASCII Be able to represent any languages CMPUT 229 - Computer Organization and Architecture I

Endianess In the previous example, there are two ways to store +1910 at the address 0x10001000 and -10510 at the address 0x10001004: 0x10001000 0x10001001 0x10001002 0x10001003 0x10001004 0x10001005 0x10001006 0x10001007 0x00 0x13 0xFF 0x97 Address Value 0x10001000 0x10001001 0x10001002 0x10001003 0x10001004 0x10001005 0x10001006 0x10001007 0x13 0x00 0x97 0xFF Address Value What is the difference? CMPUT 229 - Computer Organization and Architecture I

Little-End and Big-End +1910 = 0000 0000 0000 0000 0000 0000 0001 0011 (binary) Little end of +1910 Big end of +1910 +1910 = 0x0000 0013 (hexadecimal) -10510 = 1111 1111 1111 1111 1111 1111 1001 0111 +1910 = 0xFFFF FF97 Little end of +1910 Big end of +1910 (binary) (hexadecimal) CMPUT 229 - Computer Organization and Architecture I

Endianess The question is: which end of the integer do we store first in memory? Big end of +1910 Little end of +1910 0x10001000 0x10001001 0x10001002 0x10001003 0x10001004 0x10001005 0x10001006 0x10001007 0x00 0x13 0xFF 0x97 Address Value 0x10001000 0x10001001 0x10001002 0x10001003 0x10001004 0x10001005 0x10001006 0x10001007 0x13 0x00 0x97 0xFF Address Value Big Endian Byte Order Little Endian Byte Order DECstations and Intel 80x86 are little-endians. Sun SPARC and Macintosh are big-endians. CMPUT 229 - Computer Organization and Architecture I

CMPUT 229 - Computer Organization and Architecture I Floating Number How to represent a very large number? How about a number of the form 2.5006 x 10 Floating number IEEE standard -8 CMPUT 229 - Computer Organization and Architecture I

CMPUT 229 - Computer Organization and Architecture I IEEE 754 Floating Number S exponent fraction (precision) 1 8 23 S exponent – 127 N = -1 x 1. Fraction x 2 CMPUT 229 - Computer Organization and Architecture I

CMPUT 229 - Computer Organization and Architecture I Example 5 8 -6 CMPUT 229 - Computer Organization and Architecture I