Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Boone Exam question 70

 
Peter Chirco
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
sadesh
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic