Android 大端模式转换

public static byte[] toLH(int n) {
    byte[] b = new byte[4];
    b[0] = (byte) (n >> 0 & 0xff);
    b[1] = (byte) (n >> 8 & 0xff);
    b[2] = (byte) (n >> 16 & 0xff);
    b[3] = (byte) (n >> 24 & 0xff);
    return b;
}

public static byte[] DoubleToBytes(double d){
    //根据 IEEE 754 浮点“双精度格式”位布局,返回指定浮点值的表示形式,并保留 NaN 值。
    Long value = Double.doubleToRawLongBits(d);
    byte[] b = new byte[8];
    for(int i = 0 ; i<8;i++){
        b[i] = (byte)((value>>8*i)&0xff);
    }
    return b;
}

public static String reverseCharArray(String s) {
    if (s == null)
        s = "";
    char[] array = s.toCharArray();
    String reverse = "";
    for (int i = array.length - 1; i >= 0; i--) {
        reverse += array[i];
    }
    return reverse;
}

public static byte[] byteMerger(byte[] data) {
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    try {
        os.write(data.length);
        os.write(data);
    } catch (IOException e) {
        e.printStackTrace();
    }
    AppLog.e(DensityUtil.class, "byteMerger byte  arrry length ---> " + os.toByteArray().length);
    return os.toByteArray();
}


public static int convertByteArrToInt(byte[] byteArr, int index) {
    int intNum = 1;
    int intResult = 0;
    int ch1, ch2, ch3, ch4;
    //for(int k=index; j 
 

你可能感兴趣的:(Android,存储机制)