参考java.lang.Long.decode(String nm) Decodes a String into a Long. Accepts decimal, hexadecimal, and octal numbers given by the following grammarLong l1 = java.lang.Lang.decode("0x11");
//下面的代码我用jdk1.4试了一下 public class Hex { public static float decode(String hexNum) { int n; n=hexNum.indexOf("."); if(n==-1) { float zs=Integer.decode("0x"+hexNum).floatValue(); return zs; } else { String Z,F; int m=hexNum.length()-n-1; Z=hexNum.substring(0,n); F=hexNum.substring(n+1,hexNum.length()); float z=Integer.decode("0x"+Z).floatValue(); float f=Integer.decode("0x"+F).floatValue(); f=(float)(f/Math.pow(16,m)); return z+f; } }
public static void main(String argv[]) { System.out.println(decode("4F.3A")); } }
Decodes a String into a Long. Accepts decimal, hexadecimal, and octal numbers given by the following grammarLong l1 = java.lang.Lang.decode("0x11");
public class Hex
{
public static float decode(String hexNum)
{
int n;
n=hexNum.indexOf(".");
if(n==-1)
{
float zs=Integer.decode("0x"+hexNum).floatValue();
return zs;
}
else
{
String Z,F;
int m=hexNum.length()-n-1;
Z=hexNum.substring(0,n);
F=hexNum.substring(n+1,hexNum.length());
float z=Integer.decode("0x"+Z).floatValue();
float f=Integer.decode("0x"+F).floatValue();
f=(float)(f/Math.pow(16,m));
return z+f;
}
}
public static void main(String argv[])
{
System.out.println(decode("4F.3A"));
}
}