我有以下代码
temp = "0x00"
String binAddr = Integer.toBinaryString(Integer.parseInt(temp, 16));
为什么我会得到以下错误:
Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: "0x00"
发布于 2013-10-21 03:44:47
由于字符串包含0x
,所以使用Integer.decode(字符串nm)
String binAddr = Integer.toBinaryString(Integer.decode(temp));
发布于 2013-10-21 03:47:08
去掉javadocs中的'0x':
字符串中的字符都必须是指定基数的数字(取决于Character.digit(char,int)是否返回一个非负值),但第一个字符可能是表示负值的ASCII减号'-‘('\u002D'),也可以是ASCII加符号’'+‘('\u002B')以表示正值。返回结果的整数值。
发布于 2013-10-21 03:48:27
https://stackoverflow.com/questions/19493579
复制相似问题