成人午夜视频全免费观看高清-秋霞福利视频一区二区三区-国产精品久久久久电影小说-亚洲不卡区三一区三区一区

java整數(shù)與byte數(shù)組的轉(zhuǎn)換實(shí)現(xiàn)代碼

java整數(shù)與byte數(shù)組的轉(zhuǎn)換實(shí)現(xiàn)代碼

湞江網(wǎng)站建設(shè)公司創(chuàng)新互聯(lián),湞江網(wǎng)站設(shè)計(jì)制作,有大型網(wǎng)站制作公司豐富經(jīng)驗(yàn)。已為湞江上千多家提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\外貿(mào)網(wǎng)站制作要多少錢,請(qǐng)找那個(gè)售后服務(wù)好的湞江做網(wǎng)站的公司定做!

           這里對(duì)java中整數(shù)與byte數(shù)組的轉(zhuǎn)換進(jìn)行了實(shí)現(xiàn),平時(shí)的項(xiàng)目中很少用的到,但是特定需求的時(shí)候還是需要的,這里就記錄下,親測(cè)可用,

實(shí)現(xiàn)代碼:

public class NumberUtil { 
  /** 
   * int整數(shù)轉(zhuǎn)換為4字節(jié)的byte數(shù)組 
   * 
   * @param i 
   *      整數(shù) 
   * @return byte數(shù)組 
   */ 
  public static byte[] intToByte4(int i) { 
    byte[] targets = new byte[4]; 
    targets[3] = (byte) (i & 0xFF); 
    targets[2] = (byte) (i >> 8 & 0xFF); 
    targets[1] = (byte) (i >> 16 & 0xFF); 
    targets[0] = (byte) (i >> 24 & 0xFF); 
    return targets; 
  } 
 
  /** 
   * long整數(shù)轉(zhuǎn)換為8字節(jié)的byte數(shù)組 
   * 
   * @param lo 
   *      long整數(shù) 
   * @return byte數(shù)組 
   */ 
  public static byte[] longToByte8(long lo) { 
    byte[] targets = new byte[8]; 
    for (int i = 0; i < 8; i++) { 
      int offset = (targets.length - 1 - i) * 8; 
      targets[i] = (byte) ((lo >>> offset) & 0xFF); 
    } 
    return targets; 
  } 
 
  /** 
   * short整數(shù)轉(zhuǎn)換為2字節(jié)的byte數(shù)組 
   * 
   * @param s 
   *      short整數(shù) 
   * @return byte數(shù)組 
   */ 
  public static byte[] unsignedShortToByte2(int s) { 
    byte[] targets = new byte[2]; 
    targets[0] = (byte) (s >> 8 & 0xFF); 
    targets[1] = (byte) (s & 0xFF); 
    return targets; 
  } 
 
  /** 
   * byte數(shù)組轉(zhuǎn)換為無符號(hào)short整數(shù) 
   * 
   * @param bytes 
   *      byte數(shù)組 
   * @return short整數(shù) 
   */ 
  public static int byte2ToUnsignedShort(byte[] bytes) { 
    return byte2ToUnsignedShort(bytes, 0); 
  } 
 
  /** 
   * byte數(shù)組轉(zhuǎn)換為無符號(hào)short整數(shù) 
   * 
   * @param bytes 
   *      byte數(shù)組 
   * @param off 
   *      開始位置 
   * @return short整數(shù) 
   */ 
  public static int byte2ToUnsignedShort(byte[] bytes, int off) { 
    int high = bytes[off]; 
    int low = bytes[off + 1]; 
    return (high << 8 & 0xFF00) | (low & 0xFF); 
  } 
 
  /** 
   * byte數(shù)組轉(zhuǎn)換為int整數(shù) 
   * 
   * @param bytes 
   *      byte數(shù)組 
   * @param off 
   *      開始位置 
   * @return int整數(shù) 
   */ 
  public static int byte4ToInt(byte[] bytes, int off) { 
    int b0 = bytes[off] & 0xFF; 
    int b1 = bytes[off + 1] & 0xFF; 
    int b2 = bytes[off + 2] & 0xFF; 
    int b3 = bytes[off + 3] & 0xFF; 
    return (b0 << 24) | (b1 << 16) | (b2 << 8) | b3; 
  } 
} 

感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!

網(wǎng)站標(biāo)題:java整數(shù)與byte數(shù)組的轉(zhuǎn)換實(shí)現(xiàn)代碼
本文URL:http://jinyejixie.com/article14/ggiege.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信公眾號(hào)、網(wǎng)站設(shè)計(jì)公司、靜態(tài)網(wǎng)站、虛擬主機(jī)、Google

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

成都網(wǎng)站建設(shè)公司
龙门县| 牡丹江市| 镇雄县| 凤庆县| 宁国市| 阆中市| 灌云县| 突泉县| 青海省| 通化市| 诸城市| 金坛市| 淄博市| 杭锦旗| 且末县| 东兰县| 广州市| 金华市| 锦州市| 昭觉县| 灯塔市| 靖远县| 富顺县| 旌德县| 普兰县| 建昌县| 广安市| 工布江达县| 岑溪市| 长治县| 金湖县| 廉江市| 中山市| 洱源县| 子洲县| 孟连| 白山市| 五常市| 偃师市| 渑池县| 宜都市|