programming forums Java Java JSRs Mobile Certification Databases Caching Books Engineering OS Languages Paradigms IDEs Build Tools Frameworks Products This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Sheriffs:
Saloon Keepers:
Bartenders:

Boone Exam question 70

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:
Select the one right answer.
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

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:
Select the one right answer.
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

 It is sorta covered in the JavaRanch Style Guide.