When shifting a primitive int the shift distance is always between 0 and 31 inclusive. Just assume that the bit value of the shift distance is always "anded" with 0x1f. The binary value of -6 is 1111 1111 1111 1111 1111 1111 1111 1010 And the above with the 0x1f. 0000 0000 0000 0000 0000 0000 0001 1111 The result is 26. 0000 0000 0000 0000 0000 0000 0001 1010 I doubt that you will see a negative shift distance on the real exam, but Kathy or Bert would be a more authoritive source of information concerning what might actually appear.
Dan Chisholm<br />SCJP 1.4<br /> <br /><a href="http://www.danchisholm.net/" target="_blank" rel="nofollow">Try my mock exam.</a>
Howdy Bit Shifters - 'At this point', I don't think you'd see a negative shifting question on the exam, but the exam is not cast in stone. I think this is a valid discussion because it 'might' come up in an exam revision. There are certain topics that seem way out of scope, based on knowing some of the exam maker's philosophies, but I could imagine this one sneaking in. An example of the type of question that I don't think is likely to sneak in, is one where a detailed knowledge of precedence is required... the test makers all seem to be pretty strong advocates of parentheses. CAUTION: All of this is speculation on my part - maybe safe bets, but definitely NOT anything I'd bet my life on. (Although I'll take $5 bets ).
Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
comment >> I've felt bit shifting and bit cast representation is kind of important subject while one is dealing with network socket programming. CRC-check and encrption & decrption parts is all about bit shifiting. That's why sun ask about the question. right? I think kathy & berts book describes really well on this subject for the scjp2 test. i am enjoying the book a lot.