Data Types and Variables Part A – Introduction Numeric Data Types

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.
Computer Science 210 Computer Organization Floating Point Representation.
Binary Number Systems.
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.
1 Lecture 5 Floating Point Numbers ITEC 1000 “Introduction to Information Technology”
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 Set 4 Data Types and Variables Part A – Introduction Numeric Data Types.
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,
CSC 221 Computer Organization and Assembly Language
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.
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.
CHAPTER 5: Representing Numerical Data
Floating Point Numbers
Introduction to Numerical Analysis I
Floating Point Representations
Lecture 6. Fixed and Floating Point Numbers
Department of Computer Science Georgia State University
Fundamentals of Computer Science
Computer Science 210 Computer Organization
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
Dr. Clincy Professor of CS
Number Representation
Introduction To Computer Science
Dr. Clincy Professor of CS
Number Systems and Binary Arithmetic
Data Representation Binary Numbers Binary Addition
Floating Point Math & Representation
Chapter 6: Data Types Lectures # 10.
Tokens in C Keywords Identifiers Constants
Chapter 3 Data Storage.
Numbers in a Computer Unsigned integers Signed magnitude
Floating Point Number system corresponding to the decimal notation
CS 232: Computer Architecture II
IEEE floating point format
April 2006 Saeid Nooshabadi
Modified from Sharon Guffy
PRESENTED BY J.SARAVANAN. Introduction: Objective: To provide hardware support for floating point arithmetic. To understand how to represent floating.
Data Structures Mohammed Thajeel To the second year students
Topic 3d Representation of Real Numbers
Luddy Harrison CS433G Spring 2007
Recent from Dr. Dan Lo regarding 12/11/17 Dept Exam
Fundamentals of Programming I Number Systems
Dr. Clincy Professor of CS
How to represent real numbers
Dr. Clincy Professor of CS
ECEG-3202 Computer Architecture and Organization
C++ Data Types Data Type
Lectures on Numerical Methods
Chapter 3 DataStorage Foundations of Computer Science ã Cengage Learning.
Floating Point Numbers
Recent from Dr. Dan Lo regarding 12/11/17 Dept Exam
COMS 161 Introduction to Computing
Topic 3d Representation of Real Numbers
Floating Point Numbers
Computer Organization and Assembly Language
1.6) Storing Integer: 1.7) storing fraction:
Lecture 9: Shift, Mult, Div Fixed & Floating Point
Presentation transcript:

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

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 1/13/2019 10:08 AM

Expectations Most of this material should be old hat from CIS 1068 and 2168 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 1/13/2019 10:08 AM

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) 1/13/2019 10:08 AM

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 of the CLR) The CTS and CLS are like a standard that must be conformed to by all .NET languages What does this mean? What is a standard? Why do we have them? 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 use only Managed Types in our code 1/13/2019 10:08 AM

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 1/13/2019 10:08 AM

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) 1/13/2019 10:08 AM

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

CTS Compliant Primitive Types (Pattison) 1/13/2019 10:08 AM

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: (int)MinValue Casting example Double.Parse(s2) ‘Converts string to double ToDouble(myInteger) salesAsDecimal = Decimal.Parse(salesAsString) DateTime primitive 1/13/2019 10:08 AM

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 as of 2005 1/13/2019 10:08 AM

Integral Data Types 1/13/2019 10:08 AM

Integral Data Types (continued) 1/13/2019 10:08 AM

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 01111111 1/13/2019 10:08 AM

Understanding Integral Data Types (continued) Negative integral values appear in two’s compliment format Rules to represent a negative 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 1/13/2019 10:08 AM

Negative Two’s Complement Value Start with the positive representation of a value (What is this value?) 0010 1010 Flip each bit 1101 0101 Add one to the value from the previous step 1101 0110 1/13/2019 10:08 AM

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 1/13/2019 10:08 AM

Floating-point Data Types 1/13/2019 10:08 AM

Representation of a 32-bit Single Precision Value (optional) 1/13/2019 10:08 AM

A Brief Note on Decimal Values (optional) 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.) 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

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.  1/13/2019 10:08 AM

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 1/13/2019 10:08 AM

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 C# 1/13/2019 10:08 AM

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 1/13/2019 10:08 AM

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 1/13/2019 10:08 AM