This week's book giveaway is in the Mac OS forum. We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line! See this thread for details.
hi ranchers, In dan's operators topic exam i came through this questions, byte b=0; b+=~b>>>1; System.out.println(b); the ans is -1 the exp is b=b+~b>>>1; ==> b=0+ -1>>>1; so the result is -1. but if i compile sepreately -1>>>1,the result is 2147483647,why is that? anybody could ans me, yhx
Originally posted by anushree ari: ...but if i compile sepreately -1>>>1,the result is 2147483647,why is that?
Yes, but if you cast that result to a byte then the result will be -1. The compound assignment operator casts the result to the type of the left hand operand. If all of the 8 least significant bits are set to one then the result of a cast to a primitive byte is -1.
Dan Chisholm<br />SCJP 1.4<br /> <br /><a href="http://www.danchisholm.net/" target="_blank" rel="nofollow">Try my mock exam.</a>