aspose file tools*
The moose likes Beginning Java and the fly likes Stupid Java Question. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply locked New topic
Author

Stupid Java Question.

Milan Gupta
Greenhorn

Joined: Aug 03, 2002
Posts: 7
Okay, I feel like I'm missing something here...
For this code:
int i = 1;
System.out.println("i = " + i );
System.out.println("i as binary = " + new Integer(i).toBinaryString(i) );
i <<= 31;
System.out.println("\n\ni = " + i );
System.out.println("i as binary = " + new Integer(i).toBinaryString(i) );
i >>= 31;
System.out.println("\n\ni = " + i );
System.out.println("i as binary = " + new Integer(i).toBinaryString(i) );
System.out.println("value of 11111111111111111111111111111111 = " + new Integer(i).parseInt("-1111111111111111111111111111111", 2));
System.out.println("value of = 10000000000000000000000000000001 " + new Integer(i).parseInt("-0000000000000000000000000000001", 2));

I don't understand why i after >>=31 operation would print out "11111111111111111111111111111111" as binary representation but prints out -1 as in int.
I thought "10000000000000000000000000000001" would be -1 and "11111111111111111111111111111111" would be -2147483647 as the code prints out with parseInt call.
Milan
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Follow-ups go to the new, improved version here.


"I'm not back." - Bill Harding, Twister
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Stupid Java Question.