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

for*_*t17 3 java java-ee

System.out.println(Integer.parseInt("4B5CE3D77A73",16);
Run Code Online (Sandbox Code Playgroud)

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

我在这里想念一下吗?

Pac*_*ato 8

看起来这个数字大于Integer可以容纳的数字.试试Long:

Long.parseLong("4B5CE3D77A73",16)
Run Code Online (Sandbox Code Playgroud)

文档说它会抛出NumberFormatException - if the string does not contain a parsable integer.不仅如果字符串包含无效字符,而且如果数字大于Integer.MAX_VALUE.