CIT 383: Administrative ScriptingSlide #1 CIT 383: Administrative Scripting Numbers.

Slides:



Advertisements
Similar presentations
ECE 331 – Digital System Design
Advertisements

Types and Arithmetic Operators
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.
18-May-15 Numbers. 2 Bits and bytes A bit is a single two-valued quantity: yes or no, true or false, on or off, high or low, good or bad One bit can distinguish.
Integer Types. Bits and bytes A bit is a single two-valued quantity: yes or no, true or false, on or off, high or low, good or bad One bit can distinguish.
CIS 234: Using Data in Java Thanks to Dr. Ralph D. Westfall.
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.
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.
JavaScript, Fourth Edition
Chapter 2 Data Types, Declarations, and Displays
ECE 301 – Digital Electronics Course Introduction, Number Systems, Conversion between Bases, and Basic Binary Arithmetic (Lecture #1)
ECE 331 – Digital System Design
CIT 383: Administrative ScriptingSlide #1 CIT 383: Administrative Scripting RSS.
String Escape Sequences
CHAPTER 3: CORE PROGRAMMING ELEMENTS Introduction to Computer Science Using Ruby (c) 2012 Ophir Frieder et al.
Data Types. Every program must deal with data The data is usually described as a certain type This type determines what you can do with the data and how.
Storing data Getting data out Data types Ruby as a foundation Program Variables Click icon to hear comments (the download may take a minute)
Simple Data Type Representation and conversion of numbers
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to C++ Programming Outline Introduction to C++ Programming A Simple Program: Printing a.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2: Introduction to C++ Starting Out with C++ Early Objects Seventh.
CIT 383: Administrative ScriptingSlide #1 CIT 383: Administrative Scripting XML.
CIT 383: Administrative ScriptingSlide #1 CIT 383: Administrative Scripting Introduction.
Copyright 2006 Addison-Wesley Brief Version of Starting Out with C++ Chapter 2 Introduction to C++
CIT 383: Administrative Scripting
Data Representation in Computer Systems
CS1 Lesson 2 Introduction to C++ CS1 Lesson 2 -- John Cole1.
Representing numbers and Basic MATLAB 1. Representing numbers  numbers used by computers do not behave the same as numbers used in mathematics  e.g.,
CIT 383: Administrative ScriptingSlide #1 CIT 383: Administrative Scripting Writing Methods.
Computer Systems Architecture Copyright © Genetic Computer School 2008 CSA 1- 0 Lesson 1 Number System.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
CPS120: Introduction to Computer Science
CSC 221 Computer Organization and Assembly Language
16. Binary Numbers Programming in C++ Computer Science Dept Va Tech August, 1999 © Barnette ND, McQuain WD, Keenan MA 1 Binary Number System Base.
CIT 383: Administrative ScriptingSlide #1 CIT 383: Administrative Scripting Methods and Hashes.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 2: Variables & Data Types.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
PHY-102 SAPVariables and OperatorsSlide 1 Variables and Operators In this section we will learn how about variables in Java and basic operations one can.
CIT 383: Administrative ScriptingSlide #1 CIT 383: Administrative Scripting Regular Expressions.
1 COMS 261 Computer Science I Title: C++ Fundamentals Date: September 9, 2005 Lecture Number: 6.
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
CIT 383: Administrative ScriptingSlide #1 CIT 383: Administrative Scripting Directories.
Introduction ABAP Fields and Variables. Slide 2 Fields (Introduction) In ABAP, fields (or data objects) are named locations in memory Variables store.
CIT 383: Administrative ScriptingSlide #1 CIT 383: Administrative Scripting DateTime.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2 Introduction to C++
Java Basics. Tokens: 1.Keywords int test12 = 10, i; int TEst12 = 20; Int keyword is used to declare integer variables All Key words are lower case java.
CIT 383: Administrative ScriptingSlide #1 CIT 383: Administrative Scripting Commands.
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.
Numbers Mar 27, 2013.
Chapter 2: Introduction to C++
Number Systems and Binary Arithmetic
ECE Application Programming
CIT 383: Administrative Scripting
CIT 383: Administrative Scripting
Chapter 2: Introduction to C++
CIT 383: Administrative Scripting
2.1 Parts of a C++ Program.
Lecture 2 Python Programming & Data Types
Basics of ‘C’.
CIT 383: Administrative Scripting
C++ Data Types Data Type
CIT 383: Administrative Scripting
ECE 301 – Digital Electronics
Lecture 2 Python Programming & Data Types
CIT 383: Administrative Scripting
Chapter 2: Introduction to C++.
CIT 383: Administrative Scripting
Numbers 27-Apr-19.
Numbers 6-May-19.
CIT 383: Administrative Scripting
CIT 383: Administrative Scripting
Presentation transcript:

CIT 383: Administrative ScriptingSlide #1 CIT 383: Administrative Scripting Numbers

CIT 383: Administrative Scripting Types of Numbers Integers  Numbers without decimal points.  -3, 0, 2,  Precise operations.  = 3  1 – 2 = -1  1 * 2 = 2  1 / 2 = 0 Floats  Numbers with decimal points.  , 0.0, 3.14  Rounding errors.  = 3.0  1.0 – 2.0 = -1.0  1.0 * 2.0 = 2.0  1.0 / 2.0 = 0.5

CIT 383: Administrative Scripting Why Two Types of Numbers? Different uses –Money calculations should avoid rounding. –Measurements must often be floats. Performance –Floats take more space than integers. (usually) –CPU has separate integer and float units.

CIT 383: Administrative ScriptingSlide #4

CIT 383: Administrative Scripting Two Types of Integers Fixnum –32-bit machine integer –Fast (calculations in hardware) –Ranges from to 2 31 – 1 –Ruby promotes to Bignum beyond range. Bignum –Arbitrary precision integer –Slow (calculations in software) –No limit to size.

CIT 383: Administrative Scripting Types of Numbers Numeric Fixnum IntegerFloat Bignum

CIT 383: Administrative Scripting Integer Literals Different bases Decimal: 255 Octal: 0377 Binary: 0b Hexadecimal: 0xFF Readability Insert _ as thousands separator. Can write as 1_000_000_000

CIT 383: Administrative Scripting Float Literals Always need a decimal point 1 is an integer, 1.0 is a float Scientific notation Avogadro’s number is e23 Readability 1_000_000_000.0

CIT 383: Administrative Scripting Arithmetic Operators Addition: == 10 Subtraction: - 7 – 3 == 4 Multiplication: * 7 * 3 == 21 Division: / 13 % 2 == 6 Remainder: % 13 % 2 == 1 Exponentiation: ** 2**8 == 256

CIT 383: Administrative Scripting Logical Operations Return a true or false value. Equality 1 == 1 Inequality 1 != 1 Less Than 1 < 2 Greater Than 1 > 2 Less Than or Equal To 1 >= 2 Greater Than or Equal To 1 <= 1

CIT 383: Administrative Scripting Floating Point Rounding Machine floats –Stored as binary fractions: ½, ¼, etc. –Decimal fractions: 0.1 cannot be exactly represented, as it’s repeating in binary like 1/3. Don’t use equality tests for floats 0.4 – 0.3 == 0.1 is false Check if difference is sufficiently small (0.4 – 0.3) – 0.1 < 1.0e-9 is true

CIT 383: Administrative Scripting Variables Variables allow us to name values x = 1.0 # Assigns the value 1.0 to x x # A variable reference, evals to 1.0 Variable naming –Valid characters: letters, numbers, _ –Name must start with letter or _ –Case sensitive: now, noW, nOw are different –If name starts with capital, it is a constant. –Examples: x, y2, new_val, _secret, PI

CIT 383: Administrative ScriptingSlide #13 References 1.Michael Fitzgerald, Learning Ruby, O’Reilly, David Flanagan and Yukihiro Matsumoto, The Ruby Programming Language, O’Reilly, Hal Fulton, The Ruby Way, 2 nd edition, Addison-Wesley, Dave Thomas with Chad Fowler and Andy Hunt, Programming Ruby, 2 nd edition, Pragmatic Programmers, 2005.