This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes >> (Propagating the sign bit) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark ">> (Propagating the sign bit)" Watch ">> (Propagating the sign bit)" New topic
Author

>> (Propagating the sign bit)

B. Kelly
Greenhorn

Joined: Jun 11, 2004
Posts: 5
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
Chris Allen
Ranch Hand

Joined: Feb 01, 2003
Posts: 127
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
B. Kelly
Greenhorn

Joined: Jun 11, 2004
Posts: 5
I will check that out. It wasn't really a line of code, it was something like this:

a 1110011011001101

a>>3 1111110011011001

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 ]
Chris Allen
Ranch Hand

Joined: Feb 01, 2003
Posts: 127
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: >> (Propagating the sign bit)