gpt4 book ai didi

java - 将十六进制字符串解析为 int 值时出现意外的 NumberFormatException

转载 作者:行者123 更新时间:2023-12-01 07:35:46 25 4
gpt4 key购买 nike

我想解析一个包含 8 个十六进制数字(4 个字节)的字符串,但出现 NumberFormatException。这里出了什么问题?

assertThat(Integer.parseInt("FFFF4C6A",16),is(0xFFFF4C6A));

最佳答案

您的数字代表的数字大于可分配给 int 的数字。尝试:

Long.parseLong("FFFF4C6A", 16);

给出 4294921322。

来自doc :

An exception of type NumberFormatException is thrown if any of the following situations occurs:

  • The first argument is null or is a string of length zero.
  • The radix is either smaller than Character.MIN_RADIX or larger than Character.MAX_RADIX.
  • Any character of the string is not a digit of the specified radix, …
  • The value represented by the string is not a value of type int.

这是您遇到的第四个案例。

关于java - 将十六进制字符串解析为 int 值时出现意外的 NumberFormatException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12403212/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com