Unexpected NumberFormatException while parsing a hex string to an int value

后端 未结 5 1513
小鲜肉
小鲜肉 2021-01-26 02:22

I want to parse an String containing 8 hex-digits (4bytes) but i got an NumberFormatException. What is wrong here?

assertThat(Integer.parseInt(\"FFFF4C6A\",16),i         


        
5条回答
  •  忘了有多久
    2021-01-26 02:55

    You've exceeded the range of an integer.

    Integer.MAX_VALUE = 2147483647
    0xFFFF4C6A = 4294921322
    

    Parsing it as a Long works:

    Long.parseLong("FFFF4C6A",16)
    

提交回复
热议问题