读取8个字节转换为BigInteger数据

为了将8位二进制的数据读取为无符号的整数型数值,采取DataInputStream中的readInt()方法思想,将二进制数据读取为BigInteger类型。

1.//读取文件,解析数据
DataInputStream dis=new DataInputStream(new BufferedInputStream(new FileInputStream(file)));
2.//读取数据并转换

public static BigInteger readData(){
BigInteger b1=new BigInteger(""+
dis.read());
b1=b1.shiftLeft(0);
BigInteger b2=new BigInteger(""+dis.read());
b2=b2.shiftLeft(8);
BigInteger b3=new BigInteger(""+dis.read());
b3=b3.shiftLeft(16);
BigInteger b4=new BigInteger(""+dis.read());
b4=b4.shiftLeft(24);
BigInteger b5=new BigInteger(""+dis.read());
b5=b5.shiftLeft(32);
BigInteger b6=new BigInteger(""+dis.read());
b6=b6.shiftLeft(40);
BigInteger b7=new BigInteger(""+dis.read());
b7=b7.shiftLeft(48);
BigInteger b8=new BigInteger(""+dis.read());
b8=b8.shiftLeft(56);

BigInteger res=b1.add(b2).add(b3).add(b4).add(b5).add(b6).add(b7).add(b8);

return res;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值