Consider the following specification of a laptop to answer the next two question
ID: 3903335 • Letter: C
Question
Consider the following specification of a laptop to answer the next two questions.
Windows 7 Enterprise
Processor: Intel(R) Core(TM) i3-5005U CPU @ 2.00GHz
Installed memory(RAM) 8.00 GB (7.71 GB usable)
System type: 64-bit Operating System
What is the cycle time of the above lap-top?
1/5005 sec
1/ (2 * 109) sec
1/8 sec
1/7.71 sec
Unsigned Integer Representation
Consider the following Java program to answer questions 14 – 15.
Java implements char data type as
unsigned integer with size 2 bytes.
Note that, 216 = 65536
public static void main(String[] args) {
char A = 65535, B = 0;
System.out.println((int)++A);
System.out.println((int)--B);
}
What will be printed in the first line? Why?
a. 65536, because A will be pre-incremented before printing
b. 65535, because 65535 is the largest possible number in 2-byte unsigned representation. A cannot be incremented.
c. 0, because 65535 is the largest possible number in 2-byte unsigned representation. ++A will overflow to the smallest possible number
d. Nothing will be printed.
What will be printed in the second line? Why?
a. -1, because B will be pre-decremented before printing
b. 0, because 0 is the smallest possible number in 2-byte unsigned representation. B cannot be decremented
c. 65535, because 0 is the smallest possible number in 2-byte unsigned representation. --B will overflow to the largest possible number.
d. Nothing will be printed.
What is FFFF-FFFE in 2-byte unsigned integer representation?
a.1
b. 10
c. 111
d. 110
Integer Representation – Signed Magnitude & Two’s Compliment
What is the disadvantage of signed-magnitude representation (compared to 2’s compliment representation)?
a. Two zeros
b. Requires separate hardware units for Adding & Subtracting
c. May need to compare the magnitudes of the numbers before adding or subtracting
d. All of the above
Consider the following Java program to answer questions 18 – 19.
Java implements Short data type as
2’s complement integer with size 2 bytes.
Note that, 215 = 32767
public static void main(String[] args) {
int x = 32767; y = -32768;
System.out.println(++x);
System.out.println(--y);
}
What will be printed in the first line? Why?
a. 32768, because x will be pre-incremented before printing
b. 32767, because 32767 is the largest possible number in 2-byte 2’s compliment representation. x cannot be incremented.
c. 0, because 32767 is the largest possible positive number in 2-byte 2’s compliment representation. ++x will overflow to the smallest possible positive number
d. -32768, because 32767 is the largest possible positive number in 2-byte 2’s compliment representation. ++x will overflow to the smallest possible number
What will be printed in the second line? Why?
a. -32769, because y will be pre-decremented before printing
b. -32768, because -32768 is the smallest possible number in 2-byte 2’s compliment representation. B cannot be decremented
c. 32767, because -32768 is the smallest possible number in 2-byte 2’s compliment representation. --B will overflow to the largest possible number.
d. -1, because -32768 is the smallest possible number in 2-byte 2’s compliment representation.
--B will overflow to the largest possible negative number.
Explanation / Answer
If you have any doubts, please give me comment...
first line:
c. 0, because 65535 is the largest possible number in 2-byte unsigned representation. ++A will overflow to the smallest possible number
second line:
c. 65535, because 0 is the smallest possible number in 2-byte unsigned representation. --B will overflow to the largest possible number.
65535(FFFF) - 65534(FFFE) = 1
c. May need to compare the magnitudes of the numbers before adding or subtracting
first line:
d. -32768, because 32767 is the largest possible positive number in 2-byte 2’s compliment representation. ++x will overflow to the smallest possible number
second line:
32767, because -32768 is the smallest possible number in 2-byte 2’s compliment representation. --B will overflow to the largest possible number.