What is the result of attempting to compile and run the program?
a. Prints: ffffffff,ffffffff,ffffffff
b. Prints: ffffffff,ffffffff,7fffffff
c. Prints: ffffffff,7fffffff,ffffffff
d. Prints: ffffffff,7ffffffe,7ffffffe
e. Prints: fffffffe,ffffffff,ffffffff
f. Prints: fffffffe,ffffffff,7fffffff
g. Prints: fffffffe,7fffffff,ffffffff
h. Prints: fffffffe,7fffffff,7fffffff
i. Runtime error
j. Compiletime error
k. None of the above
If the lefthand operand of a shift operator, <<, >> and >>>, is of type int, then the shift distance is always within the range of 0 to 31, inclusive; and is specified by the least significant 5 bits of the right hand operand. Similarly, if the lefthand operand of a shift operator is of type long, then the shift distance is always within the range of 0 to 63, inclusive; and is specified by the least significant 6 bits of the right hand operand. The left shift operator, <<, shifts each bit of the left operand to the left a distance specified by the shift distance. A number of bits that is equal to the shift distance are shifted out of the leftmost bit position and are lost. A number of bits that is equal to the shift distance are shifted in at the right. The signed right shift operator, >>, shifts each bit of the left operand to the right a distance specified by the shift distance. A number of bits that is equal to the shift distance are shifted out of the rightmost bit position and are lost. A number of bits that is equal to the shift distance are shifted in at the left. The value of each bit that is shifted in at the left is equal to the value of the sign bit. The signed right shift operator maintains the sign of the left operand. The unsigned right shift operator, >>>, is similar to the signed right shift operator except for the fact that each bit shifted in at the left is zero.
When you shift right ">>", all the bits are moved over one to the right, and a ZERO OR ONE is moved in DEPENDING ON THE BIT THAT WAS JUST THERE. This is usually the "sign bit" which determines whether or not the number is negative or positive. So, the same value bit is shifted in so that the sign of the number is preserved.
When you shift right without preserving the sign bit ">>>", it behaves exactly how you'd expect it to behave  by shifting a zero in. That's why the left most digit goes from "F" (1111) to "7" (0111).
EDIT: darn smilies.
[ December 19, 2003: Message edited by: Phil Chuang ]
So...each digit can be 09 af so that each shift of a digit changes the number by the power of 16?
It just seems so difficult to try and figure out what the number in hex converts to in binary to do the shift.
Am I totally making this harder than it has to be?
So now if you see the hex value 0xff then you know that the binary representation is 11111111 or 255 (15 * 16 + 15 or 16^2  1).
Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius  and a lot of courage  to move in the opposite direction.  Ernst F. Schumacher
However...you've gone and confused me again!! haha
You said:
So now if you see the hex value 0xff then you know that the binary representation is 11111111 or 255 (15 * 16 + 15 or 16^2  1).
but isn't 11111111 actually a negative number because of the 1 in the most significant position?
So the range for bytes in 2's complement form is 128 (0x80) to 127 (0x7f).
Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius  and a lot of courage  to move in the opposite direction.  Ernst F. Schumacher
signed (/+) or
unsigned (+)
For a byte (8 bits), the signed byte ranges from 128 to 127, and the unsigned byte from 0 to 255.
I think that most java numeric types are signed, with the exception of chars, tho I may be wrong.
Do not set lab on fire. Or this tiny ad:
The WEB SERVICES and JAXRS Course
https://coderanch.com/t/690789/WEBSERVICESJAXRS
