aspose file tools*
The moose likes Beginning Java and the fly likes Decrement operator 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 » Beginning Java
Bookmark "Decrement operator" Watch "Decrement operator" New topic
Author

Decrement operator

Rebecca Abraham
Ranch Hand

Joined: Feb 20, 2003
Posts: 37
Hi,
I've a doubt concerning the decrement operator. Could someone please explain the following to me:
byte y = -128;
byte x = y--;
System.out.println ("y = " + y);
Output:
y = 127

I cant figure out how the value of y became 127.
Thanks.
Rebecca
Vicken Karaoghlanian
Ranch Hand

Joined: Jul 21, 2003
Posts: 522
y-- is equivalent to y = y - 1
that is y = -128 - 1 = -129
-128 = 1000 0000
-1 = 1111 1111
1000 0000
+1111 1111
-----------
1 0111 1111
The leftmost bit is ignored, thus resulting 127


- Do not try and bend the spoon. That's impossible. Instead, only try to realize the truth. - What truth? - That there is no spoon!!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Decrement operator