File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

int i =2147483647 //(Max_Value);int j=i*2; j=?

 
sam huang
Greenhorn
Posts: 28
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The result is -2.
Why?
[ January 04, 2003: Message edited by: sam huang ]
 
John Lee
Ranch Hand
Posts: 2545
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In binary,
i = 0111 1111 1111 1111 1111 1111 1111 1111 (you can verify, this add up to 2147483647)
j = i * 2
= 1111 1111 1111 1111 1111 1111 1111 1110
First bite is 1, so j is negative.
| j | = 0000 0000 0000 0000 0000 0000 0000 0010
so j = -2
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic