zoukankan      html  css  js  c++  java
  • 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;
    }
    //*****************************************************************************
  • 相关阅读:
    无界鼠标 Mouse Without Borders
    dockerfile编辑时常用的sed命令,用来修改配置文件。
    LD_LIBRARY_PATH无效
    spark安装
    hadoop:/bin/bash: /bin/java: No such file or directory
    spark实现wordcount
    var和val的区别
    rdd的元素打印
    spark报错:invalid token
    上交所跨市场ETF申购赎回实时回报
  • 原文地址:https://www.cnblogs.com/frostbelt/p/1766793.html
Copyright © 2011-2022 走看看