120 likes | 190 Views
Mid Term. Topics. Data Representation - Number system conversion (conversions between different bases but not 2's compliment) b . Data Types and operations (Signed and Unsigned numbers also) c . Variables and constants d . String operations e . Conditionals - Selection (if/else, switch)
E N D
Topics • Data Representation - Number system conversion (conversions between different bases but not 2's compliment) • b. Data Types and operations (Signed and Unsigned numbers also) • c. Variables and constants • d. String operations • e. Conditionals - Selection (if/else, switch) • f. Loops (for , while, do-while) (no do-while tested explicitly) • g. Writing static methods with input parameters and return values
Data Representations • Data comes in many types • int, double, String, float, boolean, char • The smallest addressable data is a byte • A byte is 8 bits where each bit is a 0 or 1 • integers are stored as 4 bytes • For example if we say : • int x = 10; /* we see the following byte pattern */
Data Representations ctd.. • For example if we say : • int x = 259; /* we see the following byte pattern */ • Write the bit pattern for • int x = 520;
Hexadecimals • For convenience we can represent bit patterns in data storages using other formats • One such format is hexadecimal • Hexadecimal uses 16 digits (base 16): 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F • Each hexadecimal digit is represented by 4-bits
Hexadecimals continued • Write the following integer using hexadecimal notation
Octal • For convenience we can represent bit patterns in data storages using other formats • Another format is octal • Octal uses 8 digits (base 8): 0,1,2,3,4,5,6,7 • Each octal digit is represented by 3-bits
Octals continued • Write the following integer using octal notation. • Hint: group the bits by 3’s (from right to left)
A variable is a container A container that can hold a byte (byte) A container that can hold 2 bytes (short or char) A container that can hold 4 bytes (int) A container that can hold 8 bytes (double)
Initializing variables and changing X 10 int x = 10; x = x + 5; x = x + 20; X 15 X 35