Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is >>>= Broken?

 
Darrin Cartwright
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Wirianto Djunaidi
Ranch Hand
Posts: 210
Ruby Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic