Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!

# Boone Exam question 70

Peter Chirco
Greenhorn
Posts: 4
I have a question about shifting
Question 70: To place a 1 in the high-bit of an int named ref that�s set to 0x00000001, you can write:
A. ref >> 31;
B. ref >>= 31;
C. ref << 31;
D. ref <<= 31;
E. Shifts the bits in an integer to the left by the number of F. bits specified and fills the right-most bit with 1.
F. Shifts the bits in an integer to the left by the number of bits specified and fills the right-most bit with 0.
The answer as given in the test is d, but I thought the answer was c. I looked through the Robert Heller and Ernest book, and I cannot find a <<= shift operator anywhere.
Thanks

Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
if you use what proposed in c, then the result of the expression is lost since it is not reassigned. Since the question explicitely asks to "place a 1 in the high bit of an int named ref" you have to reassign the result to the variable ref and thus the only possible answer is d.
the operator <<= is what is called a compound assignment operator and a <<= b is equivalent to a = a << b
HIH
------------------
Valentin Crettaz
Sun Certified Programmer for Java 2 Platform

Greenhorn
Posts: 1
Originally posted by Peter Chirco:
I have a question about shifting
Question 70: To place a 1 in the high-bit of an int named ref that�s set to 0x00000001, you can write: