可以把二进制数字转成十六制么? java.lang.Integer.parseInt(String s,int radix)后面一个参数就代表了s里面包含的数字串的进制 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 下面是十进制和二进制之间的转换,你可以参考一下,也可以先把二进制转成十进制,再用楼上的方法。import java.util.*;...public double algorismTobinary(double d,int precision)//输入十进制 double和精度,输出二进制的double { Double objDouble=new Double(d); float f=objDouble.floatValue(); int i=objDouble.intValue(); String binaryStr=Integer.toBinaryString(i); String str=objDouble.toString(); int pointpos=str.indexOf("."); str="0"+str.substring(pointpos); str=takeoutZero(str); Vector vec=new Vector(); int t=0; while(!str.endsWith(".")&&t<precision ) { double td=Double.parseDouble(str); td=td*2; String tempStr=String.valueOf(td); vec.addElement(tempStr.substring(0,1)); tempStr=tempStr.substring(1,tempStr.length()); str="0"+tempStr; str=takeoutZero(str); t++; } int len=vec.size(); String resultStr="."; for(int j=0;j<len;j++) { resultStr=resultStr+vec.elementAt(j).toString(); } resultStr=binaryStr+resultStr; double resultDouble=Double.valueOf(resultStr).doubleValue(); return resultDouble; } public double binaryToalgorism(double d)//输入二进制的double,输出十进制的double { String doubleStr=String.valueOf(d); int pointpos=doubleStr.indexOf("."); int strLen=doubleStr.length(); double resultDouble=0; for(int i=0;i<strLen;i++) { if(i!=pointpos) { int pos=pointpos-i; if(pos>0) pos--; double fd=Math.pow(2,pos); double sd=Double.valueOf(String.valueOf(doubleStr.charAt(i))).doubleValue(); resultDouble=resultDouble+fd*sd; } } return resultDouble; } public String takeoutZero(String str) { String tempStr=str; while(tempStr.endsWith("0")) { tempStr=tempStr.substring(0,str.length()-1); } return tempStr; } 请问一楼的高手:java.lang.Integer.parseInt(String s,int radix),具体的是怎么用啊?比如我现在有一个byte[] bb,是十进制的,我要转成十六进制的。应该怎么用?是java.lang.Integer.parseInt(String s,int 16)么。 用如下的方法从二进制转到十六进制:Integer.toHexString(Integer.parseInt(s,2));s为你要转换的二进制串 用如下的方法从二进制转到十六进制:Integer.toHexString(Integer.parseInt(s,2));s为你要转换的二进制串 public static String toHEXString(byte b) { return (""+"0123456789ABCDEF".charAt(0xf&b>>4)+"0123456789ABCDEF".charAt(b&0xF)); } try语句抛不抛异常finally里的程序都要执行吗? 菜鸟问题,快拿分吧 简短语句,大家看看说的是什么意思? 当鼠标进去容器后,怎么可以把箭头变成(一只手) JAVA中能为一个类设置别名吗? 斑竹,高手同志们,Java如何向access里插入和读取OLE字段 java如何获取系统当前窗口的句柄并向其发送消息 大神,救命啊 我想问一下,考到SCJP的证,在去从事Java开发的年薪是多少???,有没有钱途??? 菜鸟求教,感谢各位大佬 各位老大帮我看看我的程序错在哪?? 请问我怎么样能够将一个十进制的数组,转成十六进制的。
{
Double objDouble=new Double(d);
float f=objDouble.floatValue();
int i=objDouble.intValue();
String binaryStr=Integer.toBinaryString(i);
String str=objDouble.toString();
int pointpos=str.indexOf(".");
str="0"+str.substring(pointpos);
str=takeoutZero(str);
Vector vec=new Vector();
int t=0;
while(!str.endsWith(".")&&t<precision )
{
double td=Double.parseDouble(str);
td=td*2;
String tempStr=String.valueOf(td);
vec.addElement(tempStr.substring(0,1));
tempStr=tempStr.substring(1,tempStr.length());
str="0"+tempStr;
str=takeoutZero(str);
t++;
}
int len=vec.size();
String resultStr=".";
for(int j=0;j<len;j++)
{
resultStr=resultStr+vec.elementAt(j).toString();
}
resultStr=binaryStr+resultStr;
double resultDouble=Double.valueOf(resultStr).doubleValue();
return resultDouble;
}
public double binaryToalgorism(double d)//输入二进制的double,输出十进制的double
{
String doubleStr=String.valueOf(d);
int pointpos=doubleStr.indexOf(".");
int strLen=doubleStr.length();
double resultDouble=0;
for(int i=0;i<strLen;i++)
{
if(i!=pointpos)
{
int pos=pointpos-i;
if(pos>0)
pos--;
double fd=Math.pow(2,pos);
double sd=Double.valueOf(String.valueOf(doubleStr.charAt(i))).doubleValue();
resultDouble=resultDouble+fd*sd;
}
}
return resultDouble;
}
public String takeoutZero(String str)
{ String tempStr=str;
while(tempStr.endsWith("0"))
{
tempStr=tempStr.substring(0,str.length()-1);
}
return tempStr;
}
java.lang.Integer.parseInt(String s,int radix),具体的是怎么用啊?
比如我现在有一个byte[] bb,是十进制的,我要转成十六进制的。应该怎么用?是java.lang.Integer.parseInt(String s,int 16)么。
Integer.toHexString(Integer.parseInt(s,2));
s为你要转换的二进制串
Integer.toHexString(Integer.parseInt(s,2));
s为你要转换的二进制串
{
return (""+"0123456789ABCDEF".charAt(0xf&b>>4)+"0123456789ABCDEF".charAt(b&0xF));
}