The pages of this web site are not formatted to conserve paper, but my new book (ISBN: 0-9745862-0-X) is formatted to save paper, save your printer cartridge, save a loose-leaf binder, and save money. If you prefer to work my exams from printed pages, then give your printer a rest and buy my new book.
Today, you can find my book at amazon.com.
| No. | Answer | Remark | |
|---|---|---|---|
| 1 | d | Prints: -128,127 | A byte is an 8 bit signed value; so the minimum byte value is -(27) and the maximum value is (27 - 1). |
| 2 | b | Prints: -32768,32767 | A short is a 16 bit signed value; so the minimum short value is -(215) and the maximum value is (215 - 1). |
| 3 | a | Prints: 1111111,177,127,7f |
A
byte
is an 8 bit signed value. The left most bit is the
sign bit. The sign bit is set to zero for positive numbers
and is set to one for negative numbers. The most positive
byte value is represented as a sign bit that is set to zero
and all of the other bits set to one. The
|
| 4 | c | Prints: 7f,ffff,7fff | A byte is an 8 bit signed value. A char is a 16 bit unsigned value. A short is a 16 bit signed value. The left most bit of a signed value is the sign bit. The sign bit is zero for positive numbers and one for negative numbers. The maximum byte value in hexadecimal format is 7f and in decimal format is 127. The minimum byte value in hexadecimal format is 80 and in decimal format is -128. The byte value of decimal -1 is ff in hexadecimal. |
| 5 | f | Prints: 80000000,7fffffff | An int is a 32 bit signed value. The left most bit is the sign bit. The sign bit is zero for positive numbers and one for negative numbers. |
| 6 | b d | '\u0000' to '\uffff' 0 to 65535 | A char is a 16 bit unsigned value; so none of the char values are negative and the minimum value is zero. The maximum value is 216 - 1. |
| 7 | b d f | 0x0000 to 0xffff 0 to 0177777 0 to 65535 | A char is a 16 bit unsigned value; so none of the char values are negative and the minimum value is zero. The maximum value is 216 - 1. |
| 8 | b c e | 2 3 5 | The maximum char value is 0xffff. The maximum byte value is 127 = 0x7f. The hex value 0xff is of type int, and the decimal value is 255. The maximum positive value of type byte is 127. The value 255 is beyond the range of type byte; so 255 can not be assigned to type byte without an explicit cast. The assignment expression b3 = (byte)0xff would assign the value -1 to variable b3. |