Ok, like I have mentioned in the 'meaningless drivel' forum, I am not really new to Java, but at the same time I am...long story. Anyways, I am using the book "Ivor Horton's Beginning Java 2, SDK 1.4 edition,(Wrox)" and I am only in chapter 2. They are describing the shift operators, and I understand the <<, and >>> operators, but this one is throwing me a bit. I think I have an understanding, butI am not sure. Maybe it is just the way it is worded, sign bit, that is throwing me off. I don't know if anyone out there has this same book, but if so you can see the illustration on page 69. Sorry if this is a little silly [ June 15, 2004: Message edited by: Michael Paul ]
"Yesterday is a memory. Tomorrow is a vision. But today, it's a b@*!h." - 'Life' by Zug Izland
It would be easier if the line of code you are referring to was put in the post. There is a really good primer on bit shifting operators located at Bit Operators
Joined: Jun 11, 2004
I will check that out. It wasn't really a line of code, it was something like this:
Now i think after reviewing it over and over, I think what it was trying to convey that the '101' shifts off at the right and three off the 'high order' bits were added. I think I was just getting thrown off at the high order thing. I guess I am trying to figure if the high order is always the leftmost bit? Once again, i just think it was the way it was worded, and that campfire story is very helpful. Thank you [ June 15, 2004: Message edited by: Michael Paul ]
Joined: Feb 01, 2003
You have it correct. Basically just remember that whatever is in the most significant position (i.e. the leftmost position of the value) gets repeated as the shift occurs. In this particular example, there was a 1 in this position (indicating a negative number). Each time the bits are shifted, a 1 will be 'shifted' into this position. Likewise, if there was a 0 in this position at the beginning, a 0 would always 'shift' into this position. The '>>' operator is the only operator than can preserve the sign bit, always. The '>>>' operator always shifts a 0 into the sign bit.