Often big numbers become negative

后端 未结 4 1817
面向向阳花
面向向阳花 2020-11-28 15:28

Since I started using eclipse for project euler, I noticed that big numbers sometime become a seemingly random negative numbers. I suppose this has something to do with pass

4条回答
  •  一个人的身影
    2020-11-28 15:55

    In mathematics numbers are infinite. However in computers they are not. There is MAX_VALUE for each int-like type: int, short, long. For example Integer.MAX_VALUE. When you try to increase number more than this value the number becomes negative. This way the internal binary representation of numbers work.

    int i = Integer.MAX_VALUE;
    i++; // i becomes negative. 
    

提交回复
热议问题