Lecture Set 4 Data Types and Variables Part A – Introduction Numeric Data Types.

Slides:



Advertisements
Similar presentations
Computer Engineering FloatingPoint page 1 Floating Point Number system corresponding to the decimal notation 1,837 * 10 significand exponent A great number.
Advertisements

Topics covered: Floating point arithmetic CSE243: Introduction to Computer Architecture and Hardware/Software Interface.
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.
DATA REPRESENTATION Y. Colette Lemard February
ITEC 352 Lecture 7 Binary(2). Review Homework due on Friday Questions Binary Addition Subtraction Encoding.
Chapter 1.7 Storing Fractions. Excess Notation, continued… In this notation, "m" indicates the total number of bits. For us (working with 8 bits), it.
Assembly Language and Computer Architecture Using C++ and Java
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.
Computer ArchitectureFall 2008 © August 27, CS 447 – Computer Architecture Lecture 4 Computer Arithmetic (2)
Computer Science 210 Computer Organization Floating Point Representation.
Number Systems Lecture 02.
Binary Number Systems.
Binary Representation and Computer Arithmetic
The Binary Number System
Data Representation Number Systems.
© 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
Binary Representation. Binary Representation for Numbers Assume 4-bit numbers 5 as an integer  as an integer  How? 5.0 as a real number  How?
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.
2-1 Chapter 2 - Data Representation Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Chapter Contents.
Numeric precision in SAS. Two aspects of numeric data in SAS The first is how numeric data are stored (how a number is represented in the computer). –
1 Lecture 5 Floating Point Numbers ITEC 1000 “Introduction to Information Technology”
NUMBER REPRESENTATION CHAPTER 3 – part 3. ONE’S COMPLEMENT REPRESENTATION CHAPTER 3 – part 3.
Computer Science 111 Fundamentals of Programming I Number Systems.
Chapter 1 Data Storage(3) Yonsei University 1 st Semester, 2015 Sanghyun Park.
Number Systems So far we have studied the following integer number systems in computer Unsigned numbers Sign/magnitude numbers Two’s complement numbers.
Computer Architecture
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.
Lecture Overview Introduction Positional Numbering System
Data Representation.
College of Engineering Representing Numbers in a Computer Section B, Spring 2003 COE1361: Computing for Engineers COE1361: Computing for Engineers 1 COE1361:
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,
Computer Science Engineering B.E.(4 th sem) c omputer system organization Topic-Floating and decimal arithmetic S ubmitted to– Prof. Shweta Agrawal Submitted.
9.4 FLOATING-POINT REPRESENTATION
Lecture 5. Topics Sec 1.4 Representing Information as Bit Patterns Representing Text Representing Text Representing Numeric Values Representing Numeric.
CSC 221 Computer Organization and Assembly Language
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
COMP201 Computer Systems Floating Point Numbers. Floating Point Numbers  Representations considered so far have a limited range dependent on the number.
Integer and Fixed Point P & H: Chapter 3
Irvine, Kip R. Assembly Language for Intel-Based Computers 6/e, Signed Integers The highest bit indicates the sign. 1 = negative, 0 = positive.
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
Tokens in C  Keywords  These are reserved words of the C language. For example int, float, if, else, for, while etc.  Identifiers  An Identifier is.
©Brooks/Cole, 2003 Chapter 3 Number Representation.
Binary Numbers The arithmetic used by computers differs in some ways from that used by people. Computers perform operations on numbers with finite and.
Cosc 2150: Computer Organization Chapter 9, Part 3 Floating point numbers.
Floating Point Numbers
Floating Point Representations
Lecture 6. Fixed and Floating Point Numbers
Binary Numbers The arithmetic used by computers differs in some ways from that used by people. Computers perform operations on numbers with finite and.
A brief comparison of integer and double representation
Number Systems and Binary Arithmetic
Floating Point Math & Representation
Chapter 3 Data Storage.
Data Structures Mohammed Thajeel To the second year students
Topic 3d Representation of Real Numbers
Luddy Harrison CS433G Spring 2007
Dr. Clincy Professor of CS
Data Types and Variables Part A – Introduction Numeric Data Types
Chapter 3 DataStorage Foundations of Computer Science ã Cengage Learning.
COMS 161 Introduction to Computing
Topic 3d Representation of Real Numbers
1.6) Storing Integer: 1.7) storing fraction:
Presentation transcript:

Lecture Set 4 Data Types and Variables Part A – Introduction Numeric Data Types

Slide 2 Objectives Understand the CTS and CLS Understand how to declare and process numeric data Declare and use variables Create user-defined constants and use expressions Work with intrinsic functions and methods

Slide 3 Expectations Most of this material should be old hat from CIS 1073 I will try to cover added material not covered in the book and concepts that may be difficult or new For the most part, I once again expect you to read the book and come to class with questions

Slide 4 Introduction to Data Types and Data Storage Every object and property has a data type Data types that store numbers are called numeric data types Numeric data types can be divided into two categories Some numeric data have a decimal point Some numeric data types store integral values (values without a decimal point)

Slide 5 What is a Data Type (in.NET)? The Common Type System (CTS) is a core piece of the.NET Framework architecture – part of the Common Language Infrastructure (and hence the CLR) The CTS and CLS are like a standard that must be conformed to by all.NET languages What does this mean? Types defined within this Framework are used by all.NET languages and are called managed types A Managed Type is a type that conforms to a set of rules set for the in the CTS – we can use only Managed Types in our code

Slide 6 The Role of the CTS Managed Types are the key to the interoperability of programming languages in.NET –to our ability to mix and match programming languages in.NET If each language is allowed to define its own type system, interoperability is impossible The CTS: backbone of the.NET programming model Core set of system defined types The rules for creating user defined types Every managed language such as VB, C#, J#, COBOL, C++ in the.NET Framework sits on top the same underlying programming model and type system Types that are not compilable into a CTS type cannot be used except internally within a given component That is – they are not useable by “outside” components – those not developed in the same Assembly

Slide 7 Common Language Specification (CLS) The CTS is part of a broader Common Language Specification or CLS The CLS defines the subset of types and other language features that must be supported across all managed languages – it levels the playing field across languages. Every issue of incompatibility from one language to another has to be addressed in the CLS. Examples: Three unsigned integer types are supported by C# but not VB.NET. Case sensitivity (getName vs GetName are different (method) names in C#; they are treated the same in VB.NET)

Slide 8 Data Types – The Type Inheritance Hierarchy The CTS is based on a singly rooted inheritance hierarchy (Pattison).

Slide 9 CTS Compliant Primitive Types (Pattison)

Slide 10 Primitive Types (aka Built-In Types) Primitive may be a bad choice of terms Often implies non-class based types Not so in.NET These are class-based types which have numerous shared methods and data stores Examples: Integer.MinValue Integer.MaxValue Double.Parse(s2) ‘Converts string to double DateTime primitive

Slide 11 Integral Data Types Integral data types store data that does not have a decimal point Some integral data types can store 0 or positive values Other integral data types can store both positive and negative values (and zero) Negative values are indicated by a sign bit Unsigned data types are new to Visual Studio 2005

Slide 12 Integral Data Types

Slide 13 Integral Data Types (continued)

Slide 14 Understanding Integral Data Types All integral values are stored as binary numbers The SByte data type stores its data in 8 bits 7 bits store the data 1 bit stores the value's sign The largest possible value is 2^7-1 or 127 The value has the binary pattern

Slide 15 Understanding Integral Data Types (continued) Negative integral values appear in two’s compliment format Rules to represent a two’s compliment value: Start with the binary representation of a positive number Flip each bit 0 values become 1 1 values become 0 Add one to the number produced in the previous step

Slide 16 Negative Two’s Complement Value Start with the positive representation of a value (What is this value?) Flip each bit Add one to the value from the previous step

Slide 17 Introduction to Floating-point Data Types Floating-point numbers store values with a decimal point Floating-point numbers are stored in a form of scientific notation One bit is the sign bit A 23-bit mantissa stores the fractional part of a number The characteristic (like an exponent) is stored in 8 bits using excess notation (never negative) Other peculiarities – assumed decimal point; normalized representation

Slide 18 Floating-point Data Types

Slide 19 Representation of a 32-bit Single Precision Value

Slide 20 A Brief Note on Decimal Values Values stored as being of the decimal data type consist of 128 bits. The format of decimal value is a bit peculiar. (In other words, exactly how the 128 bit are used is a little different.) The text has an error in it. 96 bits (NOT bytes) as used to store an integral value (not a string of decimal digits). There is a 32 scaling factor the essentially indicates where the decimal point is in the in the integer. What this gives you is approximately 28 decimal digits of information. As a rough computation, there is a shade more than 3 bits per decimal). signed integer value scale factor

Slide 21 More on the Decimal Type The Decimal Type is almost perfect for storing (modeling) money. The decimal "slides." If you need 8 decimal digits to the right of the decimal you have 20 remaining to use on the left. The scale factor is used to determine where the decimal is in the value stored. This is more efficient than using decimal strings and it is pretty accurate for modeling money since you have 26 decimal digits to the left of the decimal.

Slide 22 Floating Point Data – Error Analysis It’s a big deal … We model almost all information we manipulate using the computer The models are imprecise – this lack of precision has many causes Finite number of bits for the model We use base 2 values, not base 10 – some base 10 values cannot be precisely modeled in base 2 One thin dime for example 0.10 Try getting a precise representation in base 2

Slide 23 Rounding Error (Introduction) Floating-point numbers are an approximation of an actual value 1/3 or 2/3 must be rounded, for example Rounding introduces an error called rounding error The greater the precision of the data type, the smaller the rounding error The Decimal data type has the smallest rounding error and the greatest precision (around 28 decimal digits) The currency type is not supported in VB

Slide 24 Table 4-4: Rounding Errors

Slide 25 Properties of Numeric Data Types Numeric data types have constant fields that store the minimum and maximum possible values for the data type MinValue stores the minimum possible value MaxValue stores the maximum possible value

Slide 26 Performance of Numeric Data Types Performance is a key characteristic of any application Different data types have different performance characteristics Arithmetic operations using integral data types are faster than operations on floating-point data types The Decimal data type is very slow