File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Win a copy of
Customer Requirements for Developers
this week in the
Joined: Feb 20, 2003
Mar 18, 2004 02:33:00
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);
y = 127
I cant figure out how the value of y became 127.
Joined: Jul 21, 2003
Mar 18, 2004 03:35:00
y-- is equivalent to y = y - 1
that is y = -128 - 1 = -129
-128 = 1000 0000
-1 = 1111 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:
subject: Decrement operator
inc / dec Operations precedence
type casting error!
A simple calculation of -- ((-y--)
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2015