FUNADAMENTAL DATA TYPES LEARNING OBJECTIVES: TO UNDERSTAND INTEGEr AND FLOATING POINT NUMBERS TO RECOGNIZE THE LIMITATIONS OF THE NUMERIC TYPES TO UNDERSTAND.

Slides:



Advertisements
Similar presentations
CSci 1130 Intro to Programming in Java
Advertisements

 Base “primitive” types: TypeDescriptionSize intThe integer type, with range -2,147,483, ,147,483,647 4 bytes byteThe type describing a single.
Arithmetic in Computers Chapter 4 Arithmetic in Computers2 Outline Data representation integers Unsigned integers Signed integers Floating-points.
Computer Engineering FloatingPoint page 1 Floating Point Number system corresponding to the decimal notation 1,837 * 10 significand exponent A great number.
Primitive Data Types There are a number of common objects we encounter and are treated specially by almost any programming language These are called basic.
Week 2: Primitive Data Types 1.  Programming in Java  Everything goes inside a class  The main() method is the starting point for executing instructions.
Types and Variables. Computer Programming 2 C++ in one page!
©2004 Brooks/Cole Chapter 2 Variables, Values and Operations.
CIS 234: Using Data in Java Thanks to Dr. Ralph D. Westfall.
Round-Off and Truncation Errors
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
Major Numeric Data Types Unsigned Integers Signed Integer Alphanumeric Data – ASCII & UNICODE Floating Point Numbers.
1 Lecture 3 Bit Operations Floating Point – 32 bits or 64 bits 1.
22-Jun-15 Introduction to Primitives. 2 Overview Today we will discuss: The eight primitive types, especially int and double Declaring the types of variables.
Datalogi A 3: 26/9. Java Concepts chapter 4 Fundamental Data Types int (long and short) double (and float) boolean char String.
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.
Computer Science A 2: 6/2. Course plan Introduction to programming Basic concepts of typical programming languages. Tools: compiler, editor, integrated.
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.
String Escape Sequences
Floating Point Numbers.  Floating point numbers are real numbers.  In Java, this just means any numbers that aren’t integers (whole numbers)  For example…
© 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
CSCI 1100/1202 January 16, Why do we need variables? To store intermediate results in a long computation. To store a value that is used more than.
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.
1 Number Types  Every value in Java is either: 1.a reference to an object or 2.one of the eight primitive types  eight primitive types: a.four integer.
Georgia Institute of Technology Introduction to Java, and DrJava Barb Ericson Georgia Institute of Technology Aug 2005.
Computer Science 111 Fundamentals of Programming I Number Systems.
Number Systems So far we have studied the following integer number systems in computer Unsigned numbers Sign/magnitude numbers Two’s complement numbers.
Information and Programs. Foundations of Computing Information –Binary numbers –Integers and Floating Point –Booleans (True, False) –Characters –Variables.
ME 142 Engineering Computation I Computer Precision & Round-Off Error.
1 Do you have a CS account? Primitive types –“ building blocks ” for more complicated types Java is strongly typed –All variables in a Java program must.
Data Types Copyright © 2006 Patrick McDermott College of Alameda
Lecture 5. Topics Sec 1.4 Representing Information as Bit Patterns Representing Text Representing Text Representing Numeric Values Representing Numeric.
 JAVA Compilation and Interpretation  JAVA Platform Independence  Building First JAVA Program  Escapes Sequences  Display text with printf  Data.
CISC105 – General Computer Science Class 9 – 07/03/2006.
Java Simple Types CSIS 3701: Advanced Object Oriented Programming.
Unit 3 Lesson 4 How Data Types Affect Calculations Dave Clausen La Cañada High School.
Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved. int: integers, no fractional part: 1, -4, 0 double : floating-point.
1 Number Systems Lecture 10 Digital Design and Computer Architecture Harris & Harris Morgan Kaufmann / Elsevier, 2007.
1 Representation of Data within the Computer Oct., 1999(Revised 2001 Oct)
Floating-Point Representation We can store integers and characters easily in binary, but what about fractions? ¼ =.25 = 2.5 * *
Java Programming, Second Edition Chapter Two Using Data Within a Program.
COMP Primitive and Class Types Yi Hong May 14, 2015.
Floating Point Numbers Representation, Operations, and Accuracy CS223 Digital Design.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
Variables Symbol representing a place to store information
1.2 Primitive Data Types and Variables
IT11004: Data Representation and Organization Floating Point Representation.
Types Chapter 2. C++ An Introduction to Computing, 3rd ed. 2 Objectives Observe types provided by C++ Literals of these types Explain syntax rules for.
 Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory. 
Primitive Data Types. int This is the type you are familiar with and have been using Stores an integer value (whole number) between -2,147,483,648 (-2.
CS0007: Introduction to Computer Programming Primitive Data Types and Arithmetic Operations.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
Fundamentals 2.
Floating Point Representations
ME 142 Engineering Computation I
Number Representation
Data Representation Binary Numbers Binary Addition
Chapter 4 – Fundamental Data Types
EPSII 59:006 Spring 2004.
Chapter 2.
How to represent real numbers
Chapter 2: Java Fundamentals
Storing Negative Integers
Chapter 2: Java Fundamentals
Variables and Constants
Presentation transcript:

FUNADAMENTAL DATA TYPES LEARNING OBJECTIVES: TO UNDERSTAND INTEGEr AND FLOATING POINT NUMBERS TO RECOGNIZE THE LIMITATIONS OF THE NUMERIC TYPES TO UNDERSTAND THE USE OF CONSTANTS

NUMBER TYPES TYPEDESCRIPTIONSIZE intThe integer type with range -2,147,483,648 – 2,147483,647 4 bytes byteA single byte, with range -128 ….1271 byte short the short integer type, with range - 32, ,767 2 bytes longThe long integer type, with range - 9,223,372,036,854,775,808 …9,223,372,036,854,775,807 8 bytes floatThe double-precision floating-point the with range of about bytes charThe character type represent code units in the Unicode encoding scheme 2 bytes booleanThe type with the two truth values false and true 1 bit

Overflow using ints Calculations involving integers can overflow. This happens if the result of the computation exceeds the range for the number type. For example:int n= ; System.out.println(n*n); //prints the result is truncated to fit into an int,

Floating point number limitations The double type has about 15 significant digits, and there are many numbers that cannot be accurately represented as double numbers. Not every value can be represented prisely. Therefore numbers are rounded to the nearest match. For example: double f=4.35; System.out.println(100*f); prints

How do computers represent numbers? Binary There is no exact representation to the fractional parts of a number. 1/3= Therefore the double type is not appropriate for financial calculations. Professional Programmers usethe BigDecimal type

Big Numbers Big numbers are objects of the BigInteger and BigDecimal classes in the java.math package. Big number objects have essentially no limits on their size and precision. Computation is slower than those that involve number types. You cannot use (+,*,-), instead you have to use methods called add, subtract, and multiply

Constants Constant values do not change and have special significance for computation. Once the value is set, it cannot change. Constants are declared using all CAPs final double QUARTER_VALUE =.025; final double DIME_VALUE=0.1;