COMPUTER 2430 Object Oriented Programming and Data Structures I

Slides:



Advertisements
Similar presentations
How to Convert Decimal Numbers to Binary EXAMPLES.
Advertisements

Spring 2013 Advising Starts this week! CS2710 Computer Organization1.
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.
Topics covered: Floating point arithmetic CSE243: Introduction to Computer Architecture and Hardware/Software Interface.
Princess Sumaya Univ. Computer Engineering Dept. Chapter 3:
Princess Sumaya Univ. Computer Engineering Dept. Chapter 3: IT Students.
Floating Point Representation in Computers Floating Point Numbers - What are they? Floating Point Representation Floating Point Operations Where Things.
COMP3221: Microprocessors and Embedded Systems Lecture 14: Floating Point Numbers Lecturer: Hui Wu Session 2, 2004.
Number Systems Standard positional representation of numbers:
1 Lecture 3 Bit Operations Floating Point – 32 bits or 64 bits 1.
CS180 Recitation 3. Lecture: Overflow byte b; b = 127; b += 1; System.out.println("b is" + b); b is -128 byte b; b = 128; //will not compile! b went out.
1 Binary Arithmetic, Subtraction The rules for binary arithmetic are: = 0, carry = = 1, carry = = 1, carry = = 0, carry =
Floating Point Numbers
Representation and Conversion of Numeric Types 4 We have seen multiple data types that C provides for numbers: int and double 4 What differences are there.
Binary numbers. 1 Humans count using decimal numbers (base 10) We use 10 units: 0, 1, 2, 3, 4, 5, 6, 7, 8 and (5.
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.
Floating Point Numbers.  Floating point numbers are real numbers.  In Java, this just means any numbers that aren’t integers (whole numbers)  For example…
IT 251 Computer Organization and Architecture Introduction to Floating Point Numbers Chia-Chi Teng.
Binary Real Numbers. Introduction Computers must be able to represent real numbers (numbers w/ fractions) Two different ways:  Fixed-point  Floating-point.
Computer Organization and Architecture Computer Arithmetic Chapter 9.
Computer Arithmetic Nizamettin AYDIN
1 Lecture 5 Floating Point Numbers ITEC 1000 “Introduction to Information Technology”
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI 230 Information Representation: Negative and Floating Point.
Georgia Institute of Technology Introduction to Java, and DrJava Barb Ericson Georgia Institute of Technology Aug 2005.
Fixed-Point Arithmetics: Part II
IT253: Computer Organization
Computing Systems Basic arithmetic for computers.
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.
Information and Programs. Foundations of Computing Information –Binary numbers –Integers and Floating Point –Booleans (True, False) –Characters –Variables.
Computer Architecture and Operating Systems CS 3230 :Assembly Section Lecture 10 Department of Computer Science and Software Engineering University of.
Floating Point. Agenda  History  Basic Terms  General representation of floating point  Constructing a simple floating point representation  Floating.
Floating Point (a brief look) We need a way to represent –numbers with fractions, e.g., –very small numbers, e.g., –very large numbers,
9.4 FLOATING-POINT REPRESENTATION
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 3A Integral Data (Concepts)
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.
16. Binary Numbers Programming in C++ Computer Science Dept Va Tech August, 1999 © Barnette ND, McQuain WD, Keenan MA 1 Binary Number System Base.
The Hexadecimal Number System and Memory Addressing ISAT 121.
1 Number Systems Lecture 10 Digital Design and Computer Architecture Harris & Harris Morgan Kaufmann / Elsevier, 2007.
Princess Sumaya Univ. Computer Engineering Dept. Chapter 3:
Fixed & Floating Number Format Dr. Hugh Blanton ENTC 4337/5337.
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=
CS 160 Lecture 4 Martin van Bommel. Overflow In 16-bit two’s complement, what happens if we add =
Floating Point Numbers Opening Discussion zWhat did we talk about last class? zHave you seen anything interesting in the news?
CSE 340 Simulation Modeling | MUSHFIQUR ROUF CSE340:
©Brooks/Cole, 2003 Chapter 3 Number Representation.
Fixed-point and floating-point numbers Ellen Spertus MCS 111 October 4, 2001.
The Hexadecimal System is base 16. It is a shorthand method for representing the 8-bit bytes that are stored in the computer system. This system was chosen.
973cs111_add_posneg.ppt Integers Whole numbers Do NOT contain decimal points (as in money) 43,689 is an integer 43, is NOT an integer (it is floating.
Lesson Objectives Aims You should know about: Binary numbers ‘n’ that.
Floating Point Representations
Topic: Binary Encoding – Part 2
Week 2 - Wednesday CS 121.
Lec 3: Data Representation
CIS3931 – Intro to JAVA Lecture Note Set 2 17-May-05.
Week 3 - Friday CS222.
Data Representation Binary Numbers Binary Addition
Integer Division.
EPSII 59:006 Spring 2004.
Multiple variables can be created in one declaration
COMPUTER 2430 Object Oriented Programming and Data Structures I
Topic 3d Representation of Real Numbers
How to represent real numbers
How to represent real numbers
Approximations and Round-Off Errors Chapter 3
Chapter 3 DataStorage Foundations of Computer Science ã Cengage Learning.
COMPUTER 2430 Object Oriented Programming and Data Structures I
Two’s Complement & Binary Arithmetic
Lecture 9: Shift, Mult, Div Fixed & Floating Point
Section 6 Primitive Data Types
Presentation transcript:

COMPUTER 2430 Object Oriented Programming and Data Structures I

Fixed Point Numbers Prog2 Computers need to perform floating point calculations Microprocessor chosen doesn't have a floating point capability

We use two integers to represent a double number. Fixed Point Numbers We use two integers to represent a double number. intVal qVal

How to Store Integers in Computer Binary Number 27 26 25 24 23 22 21 20 1 27 + 23 + 22 + 21 + 20 + 8 + 4 + 2 + 1 Decimal Number: 143

How to Store Signed Integers Binary Number 26 25 24 23 22 21 20 Sign bit 1 - 23 + 22 + 21 + 20 - 8 + 4 + 2 + 1 Decimal Number: -15

How to Store Signed Integers Binary Number 26 25 24 23 22 21 20 Sign bit 1 + 23 + 22 + 21 + 20 + 8 + 4 + 2 + 1 Decimal Number: +15

Prog2 Integers are 4 bytes, 32 bits We only consider positive numbers and ignore the sign

How to Store Positive Float Numbers 25 24 23 22 21 20 2-1 2-2 Implicit binary point qVal: 2 Fixed Point Number: intVal qVal

How to Store Positive Float Numbers Implicit Binary Point : qVal = 2 25 24 23 22 21 20 2-1 2-2 1 25 + 21 + 20 + 2-1 + 2-2 32 + 2 + 1 + 0.5 + 0.25 Decimal Number: 35.75

How to Store Positive Float Numbers Implicit Binary Point : qVal = 2 25 24 23 22 21 20 2-1 2-2 Decimal Number: 35.7512 35.7512 * 22 = 143.0048 = 143 1 143.0 / 22 = 35.75

Double to FixedPoint intVal = (int)(dbl * Math.pow(2, qVal)) Choose your qVal Different qVal values store the same double number with different precisions

FixedPoint to Double intVal = (int)(dbl * Math.pow(2, qVal)) dbl = intVal / Math.pow(2, qVal) You may not get the original double number!

How to Store Positive Float Numbers Fixed Point Number: qVal = 4 23 22 21 20 2-1 2-2 2-3 2-4 1 23 + 2-1 + 2-2 + 2-3 + 2-4 8 + .5 + .25 + 0.125 + 0.0625 Decimal Number: 8.9375

How to Store Float Numbers in Computer Fixed Point Number: qVal = 4 23 22 21 20 2-1 2-2 2-3 2-4 Decimal Number: 8.937567 8.937567 * 24 = 143.001072 = 143 1 143.0 / 24 = 8.9375

How to Store Data in Computer 1 Char: ? Integer 143 Fixed Point Number: qVal = 4 8.9375 Fixed Point Number: qVal = 2 37.75

Shift Operator 1 x: 40 x >> 2 New value: 10 (40 / 22 ) 1 1 x: 40 x >> 2 New value: 10 (40 / 22 ) 1 x << 2 New value: 160 (40 * 22 ) 1

Shift Operator 1 x: 40 x >> 4 New value: 2 (Underflow) 1 1 x: 40 x >> 4 New value: 2 (Underflow) 1 x << 4 New value: 128 (Overflow) 1

Prog2 We ignore overflows Underflows are not totally ignored

Shift Operator 1 x: 40 x >> -2 New value: 0 x << -2 1 x: 40 x >> -2 New value: 0 x << -2 Don’t do it!

Change qVal 1 dbl: 8.9375 Fixed Point Number: dbl * 24 dbl: 8.9375 Fixed Point Number: dbl * 24 qVal: 4, intVal: 143 Change qVal to 2: dbl * 22 (but we don’t have the original dbl any more!) intVal = intVal >> 2 8.75 (underflow) 1

Change qVal 1 dbl: 2.9375 Fixed Point Number: dbl * 24 1 dbl: 2.9375 Fixed Point Number: dbl * 24 qVal: 4, intVal: 47 Change qVal to 6: dbl * 26 intVal = intVal << 2 2.9375 (no overflow) 1

Adding Numbers Must align on the decimal point! fpn1.plus(fpn2)? 2.43 + 12.345 ? Must align on the decimal point! fpn1.plus(fpn2)? fpn1.plus(fpn2, resultQ) Must convert fpn1 and fpn2 to resultQ! Do not change either one! Use local variables!

Multiplying Numbers (not in Prog2) 2.44 * 1.2 488 244 2928 2.928 fpn1.times(fpn2, resultQ) intval: fpn1.intVal * fpn2.intVal qVal: fpn1.qVal + fpn2.qVal Must change qVal of the product to resultQ!

Method equals 1 1 Convert fpn1 to qVal 2 intVal = 37 fpn1: intVal = 149 qVal = 4 fpn1: intVal = 37 qVal = 2 1 1 Convert fpn1 to qVal 2 intVal = 37 Convert fpn2 to qVal 4 intVal = 148 1 1 Fpn1.equals(fpn2): false

Method equals 1 1 Convert fpn1 to qVal 2 intVal = 37 fpn1: intVal = 148 qVal = 4 fpn1: intVal = 37 qVal = 2 1 1 Convert fpn1 to qVal 2 intVal = 37 Convert fpn2 to qVal 4 intVal = 148 1 1 Fpn1.equals(fpn2): true

Method lessThan Convert to the smaller qVal Compare intVal after conversion When returns true, it is smaller When returns false, still could be smaller

Schedule Quiz 3: Next Monday Lab 4: Due next Wednesday Lab 5: Due following Monday Lab 6: following Wednesday Prog2: following Friday Lab4, Lab5 and Lab6 are part of Prog2

Lab 3 Put your entire UserName_Lab3 project folder under your individual folder on K:\ drive