将 mac 地址转换为整数导致数字格式异常

Converting mac address to integer resulting in number format exception

System.out.println(Integer.parseInt("4B5CE3D77A73",16);

给我一个数字格式异常。 mac 地址是从该站点生成的有效地址 http://www.miniwebtool.com/mac-address-generator/

我错过了什么吗?

该数字不适合整数,其最大值为:

System.out.println(Integer.MAX_VALUE); // prints 2147483647

尝试以下操作:

Long.parseLong("4B5CE3D77A73",16); // 0x4B5CE3D77A73 == 82862331624051

看起来这个数字大于 Integer 可以容纳的数字。尝试长:

Long.parseLong("4B5CE3D77A73",16)

Documentation 声明它抛出 NumberFormatException - if the string does not contain a parsable integer。不仅字符串包含无效字符,而且数字大于 Integer.MAX_VALUE.

我认为您应该将其转换为 hex 格式。 这可能对你有帮助。

try this