{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

ITP109_Week4

# ITP109_Week4 - Java Fundamentals Trina Gregory ITP 109...

This preview shows pages 1–12. Sign up to view the full content.

Java Fundamentals Trina Gregory ITP 109 Spring 2010

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
2 Bits and Bytes Computer Data is stored in binary using 0s & 1s The digits in a binary number are called bits 8 bits = 1 byte Binary Decimal 0000 0+0+0+0 0 0110 0+4+2+0 6 1011 8+0+2+1 11 1111 8+4+2+1 15 Binary 1 000 0 1 00 00 1 0 000 1 Exponent 2^3 2^2 2^1 2^0 Decimal 8 4 2 1 Binary Decimal 00000000 0+0+0+0+0+0+0+0 0 11111111 128+64+32+16+8+4+2+1 255
3 Bits and Bytes Hexadecimal (6+10 = 16) Every 4 bits is a single hex digit Since 4 bits can represent numbers from 0 to 15 Binary Decimal Hex 0000 0+0+0+0 0 0 1010 8+0+2+0 10 A 1011 8+0+2+1 11 B 1100 8+4+0+0 12 C 1101 8+4+0+1 13 D 1110 8+4+2+0 14 E 1111 8+4+2+1 15 F Binary Hex Decimal 0101 1010 0+4+0+1 8+0+2+0 5A 90 1100 0010 8+4+0+0 0+0+2+0 C2 194 1111 1111 8+4+2+1 8+4+2+1 FF 255

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
4 Primitive Data Types Primitive data types boolean true or false char character such as ‘a’ byte short int long float double Type Size in bits boolean 1 char 16 byte 8 short 16 int 32 long 64 float 32 double 64
5 Integral Primitive Types Type Size Minimum Maximum byte 8 bits -2^7 2^7 - 1 short 16 bits -2^15 2^15 - 1 int 32 bits -2^31 2^31 - 1 long 64 bits -2^63 2^63 - 1

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
6 Primitive Types Figure 2.1 Primitive Types
7 Types The two floating-point types are float double All the numerical primitive types except boolean and char are signed

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
8 Assignment Compatibilities Java is said to be strongly typed You can't, for example, assign a floating point value to a variable declared to store an integer Sometimes conversions between numbers are possible For example: double dNum = 7;
9 Assignment Compatibilities A value of one type can be assigned to a variable of any type further to the right byte -> short -> int -> long -> float -> double But not to a variable of any type further to the left You can assign a value of type char to a variable of type int

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
10 Type Casting A type cast temporarily changes the value of a variable from the declared type to some other type For example, double distance; distance = 9.0; int points; points = (int)distance; Illegal without (int)
11 Type Casting The value of (int)distance is 9 The value of distance , both before and after the cast, is 9.0 Any nonzero value to the right of the decimal point is truncated rather than rounded

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 39

ITP109_Week4 - Java Fundamentals Trina Gregory ITP 109...

This preview shows document pages 1 - 12. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online