• int2byte[]


    //inttobyte[]
    public static byte[] intToByteArray1(int i) {   
     byte[] result = new byte[4];   
     result[0] = (byte)((i >> 24) & 0xFF);
     result[1] = (byte)((i >> 16) & 0xFF);
     result[2] = (byte)((i >> 8) & 0xFF); 
     result[3] = (byte)(i & 0xFF);
     return result;
    }
    //or 
    public static byte[] intToByteArray2(int i) throws Exception {
    ByteArrayOutputStream buf = new ByteArrayOutputStream();   
    DataOutputStream out = new DataOutputStream(buf);   
    out.writeInt(i);   
    byte[] b = buf.toByteArray();
    out.close();
    buf.close();
       return b;
    }
    //*****************************************************************************
    //inttobyte[]
    public static byte[] intToByteArray1(int i) {
    byte[] result = new byte[4];
    result[
    0] = (byte)((i >> 24) & 0xFF);
    result[
    1] = (byte)((i >> 16) & 0xFF);
    result[
    2] = (byte)((i >> 8) & 0xFF);
    result[
    3] = (byte)(i & 0xFF);
    return result;
    }
    //or
    public static byte[] intToByteArray2(int i) throws Exception {
    ByteArrayOutputStream buf
    = new ByteArrayOutputStream();
    DataOutputStream out
    = new DataOutputStream(buf);
    out.writeInt(i);
    byte[] b = buf.toByteArray();
    out.close();
    buf.close();
    return b;
    }
    //*****************************************************************************
  • 相关阅读:
    websocket 学习笔记
    oxy 学习笔记
    postcss
    一致性hash和chord
    leveldb 学习笔记
    logrus 学习笔记
    viper 学习笔记
    redigo 学习笔记
    gin 学习笔记
    修改TOMCAT的JVM虚拟机内存大小几种方式
  • 原文地址:https://www.cnblogs.com/frostbelt/p/1766793.html
Copyright © 2020-2023  润新知