关于Java中Double型转换成十六进制的问题

       今日,小弟我做题目遇到了Double型转换成十六进制的问题,到网上找了很多方法,结果都是手动的,最后,我一狠心,自己做了一个实验,代码如下:

import java.io.*;

public class HexChange

{

 public static void main(String args[]) throws IOException

{

   File file=new File("E:\\app.bin");/*创建一个二进制文件*/

   FileOutputStream fos=new FileOutputStream(file);

  DataOutputStream dos=new DataOutputStream(fos);/*创建一个字节流*/

  double num=2.65;

  Long numtolong=Double. doubleToLongBits(num);

  Byte b1=numbertolong>>>0;

  Byte b2=numbertolong>>>8;

  Byte b3=numbertolong>>>16;

  Byte b4=numbertolong>>>24;

  Byte b5=numbertolong>>>32;

  Byte b6=numbertolong>>>40;
  Byte b7=numbertolong>>>48;

  Byte b8=numbertolong>>>56;

/*Double占8个字节*/

  dos.writeByte(b1);

  dos.writeByte(b2);

  dos.writeByte(b3);

dos.writeByte(b4);

dos.writeByte(b5);

dos.writeByte(b6);

dos.writeByte(b7);

dos.writeByte(b8);

dos.close();

fos.close();

}

}
然后你去app.bin里面看的就是2.56转换后的十六进制(记得要用Ultra Edit看这个十六进制文件哟)

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值