java - Why is 1 plus 31 zeros not a valid integer, if bit flags are 31 length, plus one negative/positive flag? -


According to

, firstly in the fourth paragraph around the table below,

In general we represent an set of values ​​on a domain of 32 values ​​(or 64, using a 64-bit integer), a 1 bit is a member that exists and is a 0 bit one that absent Will represent with the representation.

If this is true, then why is it more than 32 digit binary number Integer.MAX_VALUE ?

  System.out.println (integer parasert ("10000000000000000000000000000000000000", 2));   

Error:

  Exception in formula "main" java.lang.NumberFormatException: for input string: "10000000000000000000000000000000" java.lang.NumberFormatException.forInputString On the test.main on java.lang.Integer.parseInt (unknown source) (Test.java10)    

In base 2, 100 billion euros is 2 ^ 31 (this is 31 zeros). A 32-bit twos complementary representation of the number between a Java int 2-31 and 2 ^ 31-1 is represented; And in this course of course 2 ^ 31 is not included, this is the reason why this value can not be converted to int - although a long will be OK.

If you have Java int whose bits are 1000000000000000000000000000 (still 31 zero), that is -2 ^ 31

It is not true that the first bit integer of a Java is a positive / negative flag. This is only a digit with the place value of -2 ^ 31.

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -