Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "PROCESSING Types. Objectives Be able to convert between binary and decimal numbers. Be able to declare and initialize character variables and constants."— Presentation transcript:

1 PROCESSING Types

2 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 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 4 Decimal Numbers 123 Decimal numbers are base-10 (using digits 0-9) 1*10 2 + 2*10 1 + 3*10 0 1*100 + 2*10 + 3*1 100 + 20 + 3

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

6 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).

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

8 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

9 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 www.unicode.org.www.unicode.org 9

10 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 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 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

13 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 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 15 String Expressions Concatenation: "Joe " + "Ku"  "Joe Ku" Strings are made up of individual characters: String name = new String("Joe Ku”); name.charAt(3)  6543210 \0uK eoJ name


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

Similar presentations


Ads by Google