PROCESSING Types. Objectives Be able to convert between binary and decimal numbers. Be able to declare and initialize character variables and constants.

Slides:



Advertisements
Similar presentations
1 © 1998, 2001, 2002Calvin College, Keith Vander Linden, Jeremy D. Frens, Larry R. Nyhoff Objects (Chap. 2) Variables and Constants.
Advertisements

Primitives in Java Java has eight primitive types –boolean –integral types: signed: long, int, short, byte unsigned: char –floating point types: double,
Data Types and Expressions
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.
Constants Variables change, constants don't final = ; final double PI = ; … area = radius * radius * PI; see Liang, p. 32 for full code.
Basic C Programming Data Types and Arithmetic Operations 01/30/15.
8 November Forms and JavaScript. Types of Inputs Radio Buttons (select one of a list) Checkbox (select as many as wanted) Text inputs (user types text)
Primitive Types Java supports two kinds of types of values – objects, and – values of primitive data types variables store – either references to objects.
Chapter 2 Data Types, Declarations, and Displays
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.
Fundamental data types Horstmann Chapter 4. Constants Variables change, constants don't final = ; final double PI = ; … areaOfCircle = radius *
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…
Chapter 5 Data representation.
Computer Science 121 Scientific Computing Winter 2014 Chapter 3 Simple Types: Numbers, Text, Booleans.
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?
Representing text Each of different symbol on the text (alphabet letter) is assigned a unique bit patterns the text is then representing as.
Binary Real Numbers. Introduction Computers must be able to represent real numbers (numbers w/ fractions) Two different ways:  Fixed-point  Floating-point.
Java Primitives The Smallest Building Blocks of the Language (corresponds with Chapter 2)
Input & Output: Console
Binary, Decimal and Hexadecimal Numbers Svetlin Nakov Telerik Corporation
C Tokens Identifiers Keywords Constants Operators Special symbols.
The string data type String. String (in general) A string is a sequence of characters enclosed between the double quotes "..." Example: Each character.
CISC105 – General Computer Science Class 9 – 07/03/2006.
ITEC 1011 Introduction to Information Technologies 4. Floating Point Numbers Chapt. 5.
Primitive Variables.
1 Operations Making Things Happen (Chap. 3) Expressions.
Java Overview. Comments in a Java Program Comments can be single line comments like C++ Example: //This is a Java Comment Comments can be spread over.
CSPP58001 Floating Point Numbers. CSPP58001 Floating vs. fixed point Floating point refers to a binary decimal representation where there is not a fixed.
Floating Point in Binary 1.Place Value Chart:
Java Programming, Second Edition Chapter Two Using Data Within a Program.
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.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
Chapter2 Constants, Variables, and Data Types. 2.1 Introduction In this chapter, we will discuss –constants (integer, real, character, string, enum),symbolic.
Module B - Computation1/61 Module-B-Computation Variables Basic Memory Operations Expressions.
1.2 Primitive Data Types and Variables
ITK 168 – More Variables 10/13/05. Another example of using instance variables and constants  Go through SimpleBot  Modify SimpleBot to “teleport”
Data Representation. How is data stored on a computer? Registers, main memory, etc. consists of grids of transistors Transistors are in one of two states,
Objects Variables and Constants. Our Scuba Problem #include // cin, cout, > using namespace std; int main() { const double FEET_PER_ATM = 33.0, LBS_PER_SQ_IN_PER_ATM.
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.
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.
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.
CS 125 Lecture 3 Martin van Bommel. Overflow In 16-bit two’s complement, what happens if we add =
1 Objects Types, Variables, and Constants Chapter 3.
Basic Data Types อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา Chapter 4.
1 CE 454 Computer Architecture Lecture 4 Ahmed Ezzat The Digital Logic, Ch-3.1.
CSCI206 - Computer Organization & Programming
Floating Point Numbers
Nat 4/5 Computing Science Lesson 1: Binary
Fundamentals of Computer Science
Nat 4/5 Computing Science Data Representation Lesson 3: Storing Text
Programming and Data Structure
A brief comparison of integer and double representation
Number Representation
Introduction To Computer Science
Chapter 6: Data Types Lectures # 10.
EPSII 59:006 Spring 2004.
Binary, Decimal and Hexadecimal Numbers
CSCI206 - Computer Organization & Programming
Unit-2 Objects and Classes
Introduction to Abstract Data Types
Storing Negative Integers
How Computers Store Data
Starter Using the fingers on only one hand, what is the highest number you can count to? Rules: You must start at 1 You must count sequentially (i.e.
Variables and Computer Memory
ECE 120 Midterm 1 HKN Review Session.
Presentation transcript:

PROCESSING Types

Objectives Be able to convert between binary and decimal numbers. Be able to declare and initialize character variables and constants Understand distinctions between primitive and reference types Be able to declare and initialize String variables and constants

3 Binary Representations Binary representations use a base-2 positional numbering system. This system has only two “binary digits” (aka bits): 0 (or “off”) 1 (or “on”)

4 Decimal Numbers 123 Decimal numbers are base-10 (using digits 0-9) 1* * *10 0 1* *10 + 3*

5 Binary Numbers Binary numbers are base-2 (using digits 0 & 1) 1* * *2 0 1*4 + 1*2 + 0* = 6 10

6 Binary Encoding Systems “Groups” of bits can represent ranges of distinct values: 1 bit 2 (2 1 ) values (0 & 1) 2 bits4 (2 2 ) values (00, 01, 10, & 11) 3 bits8 (2 3 ) values … Binary representations can be used to encode anything (e.g., characters, integers and real numbers).

Representing Integers Integers are represented in twos-complement notation Here, the high-order bit indicates the sign: 2 10 = = = = = This example is shown in 16 bits, but 32 are 64 are common. 7

Representing Real Numbers Real values are often represented in 64 bits using the IEEE floating point standard: sign (1 bit) mantissa (52 bits) exponent (11 bits) 8

Representing Characters Characters are represented using one of two common schemes: ASCII Uses 7 bits, allowing for 2 7 = 128 distinct characters. Unicode Uses 16 bits, allowing for 2 16 = 65,536 distinct characters. See 9

10 Primitive Types: Characters Processing provides one character type: char Literal character expressions: 'A' ' '.' Escape characters: '\n' '\t' '\'' '\"' '\\' Processing represents individual characters using Unicode.

11 Primitive vs Reference Types Primitive types store literal values. Reference types store the address of the object representation created: The constructor pattern: new ClassName (Arguments) 42 int age = 42; 0x2ccb 79 Integer myAge = new Integer(79); age myAge 0x2ccb

12 Wrapper Classes Wrapper classes add capabilities to the primitive types. Their names are capitalized, e.g. Integer, Double, Character Character myC = new Character(‘c’); 0x4cca c myC 0x4cca

Using Wrapper Methods Character: Integer: Character myC = new Character(‘c’); char upC = Character.toUpperCase(myC); int val = Character.getNumericValue(myC); print(Integer.MAX_VALUE); Integer intValue = new Integer(2); println(intValue.doubleValue() / 4);

14 Strings Strings are text sequences of characters. Processing provides one text data type: String Literal String expressions: "Hello" "you silly English k-nih-git” String variables: String myName = new String(”Serita”); String class = “CS 108”;

15 String Expressions Concatenation: "Joe " + "Ku"  "Joe Ku" Strings are made up of individual characters: String name = new String("Joe Ku”); name.charAt(3)  \0uK eoJ name