举例:
System.out.print(Integer.parseInt("F", 16)));
结果就是:15。
你的程序在i>256时,one变成一位十六进制数了,前面缺了一个0.
在i>256时,在one前面补一个0,就行了.
完整的程序如下:(改动的地方见注释)
public class A {public static void main(String[] args) {
for (int i = 1 i < 260 i++) {
byte[] cs=new byte[2]
cs[0]=(byte) (i & 0xFF)
cs[1]=(byte) ((i/256) & 0xFF)
System.out.println("cs[0]---"+cs[0])
System.out.println("cs[1]---"+cs[1])
String one=Integer.toHexString(cs[0]&0xFF)
String two=Integer.toHexString(cs[1]&0xFF)
System.out.println("one---"+one)
System.out.println("two---"+two)
if(one.length()==1)one="0"+one//这里加一句
String thr=two+one
System.out.println(thr)
int hh=Integer.valueOf(thr,16)
System.out.println("发出的数是:"+i)
System.out.println("返回的数是:"+hh)
}
}
}