Numbers and number systems

Slides:



Advertisements
Similar presentations
Topics covered: Floating point arithmetic CSE243: Introduction to Computer Architecture and Hardware/Software Interface.
Advertisements

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.
Binary Arithmetic Binary addition Binary subtraction
Princess Sumaya Univ. Computer Engineering Dept. Chapter 3:
Princess Sumaya Univ. Computer Engineering Dept. Chapter 3: IT Students.
Floating Point Numbers
Faculty of Computer Science © 2006 CMPUT 229 Floating Point Representation Operating with Real Numbers.
1 Lecture 9: Floating Point Today’s topics:  Division  IEEE 754 representations  FP arithmetic Reminder: assignment 4 will be posted later today.
Assembly Language and Computer Architecture Using C++ and Java
Number Systems Standard positional representation of numbers:
Signed Numbers.
Assembly Language and Computer Architecture Using C++ and Java
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.
1 Module 2: Floating-Point Representation. 2 Floating Point Numbers ■ Significant x base exponent ■ Example:
Floating Point Numbers
Computer Science 210 Computer Organization Floating Point Representation.
Binary Number Systems.
School of Computer Science G51CSA 1 Computer Arithmetic.
The Binary Number System
Data Representation Number Systems.
Simple Data Type Representation and conversion of numbers
Binary Real Numbers. Introduction Computers must be able to represent real numbers (numbers w/ fractions) Two different ways:  Fixed-point  Floating-point.
Information Representation (Level ISA3) Floating point numbers.
Computer Organization and Architecture Computer Arithmetic Chapter 9.
Computer Arithmetic Nizamettin AYDIN
1 Lecture 5 Floating Point Numbers ITEC 1000 “Introduction to Information Technology”
CEN 316 Computer Organization and Design Computer Arithmetic Floating Point Dr. Mansour AL Zuair.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI 230 Information Representation: Negative and Floating Point.
IT253: Computer Organization
Computing Systems Basic arithmetic for computers.
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.
ECE232: Hardware Organization and Design
Floating Point. Agenda  History  Basic Terms  General representation of floating point  Constructing a simple floating point representation  Floating.
Data Representation in Computer Systems
Floating Point (a brief look) We need a way to represent –numbers with fractions, e.g., –very small numbers, e.g., –very large numbers,
CH09 Computer Arithmetic  CPU combines of ALU and Control Unit, this chapter discusses ALU The Arithmetic and Logic Unit (ALU) Number Systems Integer.
Oct. 18, 2007SYSC 2001* - Fall SYSC2001-Ch9.ppt1 See Stallings Chapter 9 Computer Arithmetic.
9.4 FLOATING-POINT REPRESENTATION
Fixed and Floating Point Numbers Lesson 3 Ioan Despi.
Lecture 9: Floating Point
CSC 221 Computer Organization and Assembly Language
Floating Point Arithmetic
Princess Sumaya Univ. Computer Engineering Dept. Chapter 3:
Integer and Fixed Point P & H: Chapter 3
Computer Arithmetic Floating Point. We need a way to represent –numbers with fractions, e.g., –very small numbers, e.g., –very large.
CS1Q Computer Systems Lecture 2 Simon Gay. Lecture 2CS1Q Computer Systems - Simon Gay2 Binary Numbers We’ll look at some details of the representation.
Numbers in Computers.
CS 232: Computer Architecture II Prof. Laxmikant (Sanjay) Kale Floating point arithmetic.
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 Numbers The arithmetic used by computers differs in some ways from that used by people. Computers perform operations on numbers with finite and.
COSC2410: LAB 2 BINARY ARITHMETIC SIGNED NUMBERS FLOATING POINT REPRESENTATION BOOLEAN ALGEBRA 1.
Cosc 2150: Computer Organization Chapter 9, Part 3 Floating point numbers.
1 CE 454 Computer Architecture Lecture 4 Ahmed Ezzat The Digital Logic, Ch-3.1.
Floating Point Representations
Binary Numbers The arithmetic used by computers differs in some ways from that used by people. Computers perform operations on numbers with finite and.
Dr. Clincy Professor of CS
Number Representation
CS 232: Computer Architecture II
IEEE floating point format
Data Structures Mohammed Thajeel To the second year students
Number Representations
Arithmetic Logical Unit
How to represent real numbers
How to represent real numbers
Dr. Clincy Professor of CS
Number Representations
Presentation transcript:

Numbers and number systems

Radix number systems Some number of positions and some number of symbols The number of positions varies by context The number of symbols is a property of the number system Decimal -- 10 symbols Binary -- 2 symbols Octal -- 8 symbols Hexadecimal -- 16 symbols

Start with whole numbers Each position has a value Each symbol has a value Multiply the value of the symbol by the value of the position, then add In decimal, 3874 means 3 times 1,000 plus 8 time 100 plus 7 times 10 plus 4 times 1

Decimal, binary, octal, hex In decimal there are 10 symbols (0..9) and the value of each position is a power of 10. 100 = 1 = value of the units position 101 = 10 = value of next position to the left etc. In binary, there are 2 symbols, 0 and 1, and the value of each position is a power of 2. In octal, 8 symbols, and powers of 8 In hexadecimal, 16 symbols, and powers of 16

Converting Binary to/from octal and hex is very easy mark off groups Decimal is harder, but not very much. Example 3176 to binary, octal, hex 71348 to decimal, binary, hex 5A3216 to decimal, binary, octal

Include fractions Same principles Use negative powers of the base to the right of the radix point. (Only call it a decimal point in the decimal number system.) 426.12810 to binary, octal, hex 11011.10112 to decimal, octal, hex 426.548 to decimal, binary, hex AB1.216 to decimal, binary, octal

Negatives Same as positive, but need a way to recognize that the value is negative. What does negative mean? Distance from 0, opposite direction of positive For every positive, there is a corresponding negative. When those are added, the result is exactly 0.

Ways to represent negatives Sign magnitude - or ( ) or red ink or whatever 1’s complement reverse the bits to get the negative (subtract from all 1’s to get the complement) 2’s complement subtract from a power of two 10000000 …. 000 (number of places depends on the size of the storage available.) It so happens that reversing the bits and adding 1 accomplishes this subtraction. excess something Add something to the value before storing

2’s complement For n bits, each value is expressed relative to its distance from 2n. Technically, that means subtract each value from 2n . Conveniently, that can be accomplished by switching each bit and then adding 1 to the result. For n = 4: subtract from 24 = 10000, show only four bits. 0000 0 0100 4 1000 -8 1100 -4 0001 1 0101 5 1001 -7 1101 -3 0010 2 0110 6 1010 -6 1110 -2 0011 3 0111 7 1011 -5 1111 -1 Note, 0 comes first, then the positive values, then the negatives.

Does this work? Check it out. Example: 3 + 4: Example: -3 + -4: 0011 + 0100 = 0111 = 7 Example: -3 + -4: 1101 + 1100 = 1)1001. 1001 = -7 note that the extra 1 that flows out of the computation is not an overflow. Example: +3 + -4: 0011 = 1100 = 1111 = -1 Examples don’t prove correctness, of course; they are only illustrations

Excess something The point of excess something representation for values is that numbers stay in the order you expect the greatest negative is the smallest value 0 is in the middle the greatest positive is the largest value. We will see excess 127 used in representing exponents. The value 43 would be represented as 43+127 = 170 The value -43 would be represented as -43 + 127 = 84 The smaller values (the negatives) start with 0 in binary; the larger values (the positives) start with binary 1. This is the opposite of 2’s complement, where the negatives start with 1 and the positives start with 0.

Binary arithmetic - addition 0 + 0 = 0 0 + 1 = 1 Overflow: If there is not enough room to hold the result correctly. An extra bit that drops out is not necessarily an overflow. If the two numbers are of opposite signs, no overflow can occur. (Why not?) If the numbers are of the same sign, overflow occurs if the carry into the sign bit position is different from the carry out of the sign bit position. 1 + 0 = 1 1 + 1 = 0 and carry 1 (Add two small negative nos.) (Result is smaller than one of them) Sign changed as a result of the computation, not because of the signs of the numbers used.

Binary arithmetic - multiplication 0 * 0 = 0 0 * 1 = 0 No carry. No big tables to memorize Multiplying negatives: complement, multiply the positives, set the sign appropriately. Size of the product is sum of the sizes of the multiplier and multiplicand. 1 * 0 = 0 1 * 1 = 1

Fractions A part of a whole. Approximation of the real number line, with limitations imposed by the number of places used. Consider a decimal number expressed with not more than 5 decimal places. How would you represent 0.0000138? Because of the limitation on the representation (only 5 places), we cannot accurately represent this number. Instead, we would use an approximation: 0.00001 This is an example of a roundoff error If we needed to represent the remaining 0.0000038 of the number, we are out of luck. This is called underflow

Overflow and Underflow Ref. Tannenbaum. Computer Organization

How to represent fractional values in binary We have only two symbols. We must represent numbers: 0 and 1 sign radix point How do we do that? There have been a number of perfectly good solutions. Now that it is common to exchange data between systems, we must have one common method.

Floating point notation By example (using 8 bit word size): 2.5 = 10.1 in binary One way to represent the point is to put it in the same place all the time and then not represent it explicitly at all. To do that, we must have a standard representation for a value that puts the point in the same place every time. 10.1 = 1.01 * 21 Use 1 bit for sign, 2 bits for exponent, rest for value sign = 0 (positive); exponent = 01; significand = 101 point assumed as in 1.01 Result= 00110100

Refinement Use 32 or 64 bits, not 8, to make more reasonable range of values Note that the leading 1 (as in 1.01 *21) is always there, so we don’t need to waste one of our precious bits on it. Just assume it is always there. Use excess something notation for handling negative exponents. These ideas came from existing schemes developed for the PDP-11 and CDC 6600 computers.

IEEE Standard 754 One way to meet the need, agreed to and accepted by most computer manufacturers. Bits 1 8 23 Single Precision Fraction Sign Exponent Double Precision Bits 1 11 52 Fraction Sign Exponent

Steps to IEEE format Convert 35.75, for example Convert the number to binary 100011.11 Normalize 1.0001111 x 25 Fit into the required format 5 + 127 = 132; hide the leading 1. 01000010000011110000000000000000 Use Hexadecimal to make it easier to read 420F0000

Single and double precision Double precision uses more space, allows greater magnitude and greater precision. Other than that, it behaves just like single precision. We will use only single precision in examples, but any could easily be expanded to double precision.

IEEE 754 details Ref. Tannenbaum. Computer Organization

What’s normal? Normalized means represented in the normal, or standard, notation. Some numbers do not fit into that scheme and have a separate definition. Consider the smallest normalized value: 1.000--000 x 2-126 How would we represent half of that number? 1.000--000 x 2-127 But we cannot fit 127 into the exponent field 0.100 --000 x 2-126 would do it. But we are stuck with that implied 1 before the implied point So, there are a lot of potentially useful values that don’t fit into the scheme. The solution: special rules when the exponent has value 0 (which represents -126).

Denormalization This is denormalization: abandoning the “normal” scheme to exploit possibilities that would otherwise not be available. Any non-zero value Sign No implied 1 before the implied point Power of two multiplier is -127

Representing Zero How do you represent exactly 0 if there is an implied 1 in the number somewhere? A special case of denormalized numbers, when everything is zero, the value of the number is exactly 0.0

Infinity A special representation is reserved for infinity, because it is a useful entity to have available. 11111111 00000… …000000000 Sign

NaN (Not a Number) One more special case reserved for undefined results: 11111111 Any non-zero bit pattern Sign