aspose file tools*
The moose likes Java in General and the fly likes Is >>>= Broken? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Is >>>= Broken?" Watch "Is >>>= Broken?" New topic
Author

Is >>>= Broken?

Darrin Cartwright
Ranch Hand

Joined: Dec 27, 2002
Posts: 107
Or am I just missing something.
When I try to use the "right shift with zero extension" operator, I still get 1's filling in from the left.
Can anyone tell me what I am doing wrong?
Here is a little sample program:

On the next to last line of this program I would expect 00000001 00000000 to be printed.
Please help. The cattle are restless.


Life is good on the Ponderosa,<br />but mind where you step.
Wirianto Djunaidi
Ranch Hand

Joined: Mar 20, 2001
Posts: 210

The reason is >>>= operate on int data type, so your number got converted
into int during shift and you got the erroneous result when it was truncated back. If you had used

You'll see the compiler give a warning regarding the lost of precision.
If you change your data type to int, it will show the correct result.
[ September 29, 2003: Message edited by: Wirianto Djunaidi ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Is >>>= Broken?