Either give me a copy of your problems or upload to the 12 September moodle page.
CMU 15-215 Video to view
Stuff to do
- Bases of Java literals
- decimal
235 - octal
0235710 - hexadecimal
0x235eA - binary
0b0110001010111— not in C (but in GCC) - Examples to do
- decimal ↔ binary and hexadecimal
- 235
- 2017
- binary ↔ octal ↔ hexadecimal
0b110100110106660xE1E10
- decimal ↔ binary and hexadecimal
- decimal
- Integer types of Java — C also has
unsignedtypesbyte, 8 bits — in C99,int8_tshort, 16 bits — in C99,int16_tint, 32 bits — in C99,int32_tlong, 64 bits — in C99,int64_tchar, 16 bits — in C99,uint16_t- Questions to answer
- Given the range of the signed Java types, what should be the range of C’s corresponding
unsigneddata types? - What is special about 65535?
- Given the range of the signed Java types, what should be the range of C’s corresponding
- Bitwise operators of Java
~,&,|, and^- Examples to do
~235235 & 100235 | 100235 ^ 100
- Questions to answer, for positive numbers.
- Is
x | y > x? - Is
x & y > x? - Is
x ^ y > x?
- Is
- Examples to do
- Representation of negative numbers — two’s complement only
- Negative weight to the most significant bit
- You must know the number of bits
- Examples to do in 10-bit two’s complement
235-235-100-1
- Shift operators of Java —
<<,>>,>>>(not in C)- Arithmetic vs logical right shift
- You must know the number of bits
- Examples to do in 12-bit. Assume are all signed.
235 >> 2-235 >> 2235 << 2
- Widening and narrowing casts
- Java defines widening and narrowing casts
- In C,
unsignedmakes this difficult; however, narrowing is fine, if input within the output range - References for C
- Practice problems 2.25 and 2.26 (p. 83)
- Overflow — signed and unsigned arithmetic
- If it makes no sense to the 5th grader, it is wrong!
- Examples to do in 10-bit signed
235 + 888235 + 400-235 + -100
- Examples to do in 10-bit unsigned
235 + 888235 + 400
- Optimizing multiplication and division by constants
X<<nmultiplies by 2n — if result in rangeX>>ndivides by 2n — if result in range, but rounding is downward not toward zeroZ = X*1000 ;is probably slower thanT = X<<3 ;Z = X<<10 - T - T - T ;- Practice Problem 2.40 (p. 40)