| | |
| | | package com.dayu.recharge.tools; |
| | | |
| | | import java.math.BigInteger; |
| | | import java.nio.ByteBuffer; |
| | | import java.nio.ByteOrder; |
| | | import java.util.Arrays; |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | |
| | | return Integer.toHexString(Float.floatToIntBits(value)); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 将带符号的32位浮点数装换byte数组 |
| | | * 低位在前高位在后 |
| | | * |
| | | * @param value |
| | | * @return |
| | | */ |
| | | public static byte[] folatToByte(Float value) { |
| | | ByteBuffer buffer = ByteBuffer.allocate(4); // 4个字节 |
| | | buffer.order(ByteOrder.LITTLE_ENDIAN); |
| | | buffer.putFloat(value); |
| | | byte[] byteArray = buffer.array(); |
| | | return byteArray; |
| | | } |
| | | |
| | | /** |
| | | * 将byte数组转换为带符号的32位浮点数 |
| | | * |
| | | * 低位在前高位在后 |
| | | * |
| | | * @param value |
| | | * @return |
| | | */ |
| | | public static Float bytesToFloat(byte[] value) { |
| | | ByteBuffer bufferLittleEndian = ByteBuffer.wrap(value); |
| | | bufferLittleEndian.order(ByteOrder.LITTLE_ENDIAN); |
| | | return bufferLittleEndian.getFloat(); |
| | | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 十进制转16进制 |
| | | * |
| | |
| | | |
| | | /** |
| | | * short10进制转16进制 低位在前高位在后 |
| | | * |
| | | * @param number |
| | | * @return |
| | | */ |
| | |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * short10进制转16进制 低位在前高位在后 |
| | | * |
| | | * @param number |
| | | * @return |
| | | */ |
| | |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * short16进制转10进制 低位在前高位在后 |
| | | * |
| | | * @param hex |
| | | * @return |
| | | */ |
| | | public static short getShort10To16LowHigh(String hex){ |
| | | public static short getShort10To16LowHigh(String hex) { |
| | | try { |
| | | String str = ""; |
| | | str = spaceHex(hex); |
| | | str = HighLowHex(str); |
| | | return (short) Integer.parseInt(str, 16); |
| | | } catch (NumberFormatException e) { |
| | | e.printStackTrace(); |
| | | e.printStackTrace(); |
| | | } |
| | | return 0; |
| | | } |