Java, Long.parse binary String

后端 未结 6 2053
灰色年华
灰色年华 2020-12-17 20:04

Why does this code throw a NumberFormatException :

String binStr = \"1000000000000000000000000000000000000000000000000000000000000000\";
System         


        
6条回答
  •  忘掉有多难
    2020-12-17 20:30

    This is the largest possible long (9223372036854775807 = 2 exp 63 - 1) in binary format. Note the L at the end of the last digit.

     long largestLong = 0B0111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111L;
    

提交回复
热议问题