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;
    }
    //*****************************************************************************
  • 相关阅读:
    Android数据的四种存储方式SharedPreferences、SQLite、Content Provider和File (二) —— SQLite
    理解 Continuation
    99种用Racket说I love you的方式
    Racket Cheat Sheet
    scheme 教程 #lang racket
    开始学习Scheme
    MIT Scheme 的基本使用
    CPS变换
    SECD machine
    scheme 之门
  • 原文地址:https://www.cnblogs.com/frostbelt/p/1766793.html
Copyright © 2011-2022 走看看