double类型如何转化为字节数组? double类型如何转化为字节数组? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 也许这是你想要的。~public class bd { public static void main(String[] args){ byte[] b={10,20,30}; long[] a = new long[b.length]; double[] d=new double[b.length]; for (int i = 0; i < b.length; i++) { a[i] = (long) b[i]; d[i] = Double.longBitsToDouble(a[i]); System.out.println(d[i]); } }} 我也是个初学者 不知道对不对喔~ 根据楼上的改改了改,不晓得对不对哦 public static void main(String[] args) { byte[] b={10,20,30}; long[] a = new long[b.length]; double[] d=new double[b.length]; d[0]=12.0;d[1]=13.0; for (int i = 0; i < b.length; i++) { a[i] = (long) d[i]; b[i]=Byte.parseByte(String.valueOf(a[i])); System.out.println(b[i]); } } 不明白楼主的意思,double占8个字节,难道是要转成IEEE754 64位双精度浮点数的计算机内部表示? public class DoubleTest { public static void main(String[] args) { double numPI = Math.PI; byte[] bytes = double2bytes(numPI); // 输出 for(int i = 0; i < bytes.length; i++) { System.out.printf("%4d", bytes[i]); } } public static byte[] double2bytes(double num) { long nums = Double.doubleToLongBits(num); byte[] bytes = new byte[Double.SIZE / Byte.SIZE]; // 0为高位字节,7为低位字节 for(int i = 0; i < bytes.length; i++) { bytes[bytes.length - i - 1] = (byte)((nums >> (i * 8)) & 0xff); } return bytes; }} double d = 3.101; String s = String.valueof(d); byte[] b = s.getBytes(); ByteArrayOutputStream baos=new ByteArrayOutputStream();DataOutputStream dos=new DataOutputStream(baos);dos.writeDouble(0.5);//写入double值byte[] b=baos.toByteArray(); java操作指定list问题 JSP或Java调用Httpclient抓取网页,如何判断抓取完毕? web程序中怎么实现每天夜里3:30向数据库中自动插入一条记录(高分送,在线等) 请问怎么在JAVA中·把已有的信息进行修改和追加··· 程序员几岁算老? java中调用带记录集的存储过程时,存储过程中的游标参数在java中怎么传,来都有分,有解即结! 布局 谁有收藏的适合初学者学习csdn里的好的帖子把网址发过来好么? ¥¥¥ 如何在一个类中引用另一个类的方法。 LinkedList.poll() 问题 我下了一个apacher的包 杂个用? hibernate 查询问题
public class bd { public static void main(String[] args){
byte[] b={10,20,30};
long[] a = new long[b.length];
double[] d=new double[b.length];
for (int i = 0; i < b.length; i++) {
a[i] = (long) b[i];
d[i] = Double.longBitsToDouble(a[i]);
System.out.println(d[i]);
}
}
}
我也是个初学者 不知道对不对喔~
byte[] b={10,20,30};
long[] a = new long[b.length];
double[] d=new double[b.length];
d[0]=12.0;d[1]=13.0;
for (int i = 0; i < b.length; i++) {
a[i] = (long) d[i];
b[i]=Byte.parseByte(String.valueOf(a[i]));
System.out.println(b[i]);
} }
public static void main(String[] args) {
double numPI = Math.PI;
byte[] bytes = double2bytes(numPI);
// 输出
for(int i = 0; i < bytes.length; i++) {
System.out.printf("%4d", bytes[i]);
}
}
public static byte[] double2bytes(double num) {
long nums = Double.doubleToLongBits(num);
byte[] bytes = new byte[Double.SIZE / Byte.SIZE];
// 0为高位字节,7为低位字节
for(int i = 0; i < bytes.length; i++) {
bytes[bytes.length - i - 1] = (byte)((nums >> (i * 8)) & 0xff);
}
return bytes;
}
}
double d = 3.101;
String s = String.valueof(d);
byte[] b = s.getBytes();
ByteArrayOutputStream baos=new ByteArrayOutputStream();
DataOutputStream dos=new DataOutputStream(baos);
dos.writeDouble(0.5);//写入double值
byte[] b=baos.toByteArray();