乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      Java中byte數(shù)組與long數(shù)組相互轉(zhuǎn)化

       nacy2012 2015-11-10
      Java中byte數(shù)組與long數(shù)組相互轉(zhuǎn)化
      ByteAndLongArrayTest代碼如下:
      1. package com.array.test;
      2. import java.io.IOException;
      3. /**
      4.  * @ version 1.0
      5.  * @ author  wangwei
      6.  * @ created on  2008-10-17
      7.  */
      8. public class ByteAndLongArrayTest {
      9.     /**
      10.      * long數(shù)組轉(zhuǎn)化為byte數(shù)組
      11.      * 
      12.      * @param longArray
      13.      * @return
      14.      * @throws IOException
      15.      */
      16.     public static byte[] longToByte(long[] longArray)throws IOException{
      17.         byte[] byteArray=new byte[longArray.length*8];
      18.         for(int i=0;i<longArray.length;i++)
      19.         {
      20.             byteArray[0+8*i]=(byte)(longArray[i]>>56);
      21.             byteArray[1+8*i]=(byte)(longArray[i]>>48);
      22.             byteArray[2+8*i]=(byte)(longArray[i]>>40);
      23.             byteArray[3+8*i]=(byte)(longArray[i]>>32);
      24.             byteArray[4+8*i]=(byte)(longArray[i]>>24);
      25.             byteArray[5+8*i]=(byte)(longArray[i]>>16);
      26.             byteArray[6+8*i]=(byte)(longArray[i]>>8);
      27.             byteArray[7+8*i]=(byte)(longArray[i]>>0);
      28.         }
      29.         return byteArray;
      30.     }
      31.     
      32.     /**
      33.      * byte數(shù)組轉(zhuǎn)化為long數(shù)組
      34.      * 
      35.      * @param byteArray
      36.      * @return
      37.      * @throws IOException
      38.      */
      39.     public static long[] byteToLong(byte[] byteArray)throws IOException{
      40.         
      41.         long [] longArray=new long[byteArray.length/8];
      42.         for(int i=0;i<longArray.length;i++)
      43.         {
      44.             longArray[i]=(((long)byteArray[0+8*i]&0xff)<<56)
      45.                         |(((long)byteArray[1+8*i]&0xff)<<48)
      46.                         |(((long)byteArray[2+8*i]&0xff)<<40)
      47.                         |(((long)byteArray[3+8*i]&0xff)<<32)
      48.                         |(((long)byteArray[4+8*i]&0xff)<<24)
      49.                         |(((long)byteArray[5+8*i]&0xff)<<16)
      50.                         |(((long)byteArray[6+8*i]&0xff)<<8)
      51.                         |(((long)byteArray[7+8*i]&0xff)<<0);
      52.             
      53.         }
      54.         return longArray;
      55.     }
      56.     /**
      57.      * @param args
      58.      */
      59.     public static void main(String[] args) throws Exception{
      60.         // TODO Auto-generated method stub
      61.         long [] longArray={1,2,3,4,500000};
      62.         byte [] byteArray=longToByte(longArray);
      63.         for(int i=0;i<byteArray.length;i++)
      64.         {
      65.             System.out.print(byteArray[i]+" ");
      66.         }
      67.         System.out.println();
      68.         long [] longArray2=byteToLong(byteArray);
      69.         for(int i=0;i<longArray.length;i++)
      70.             System.out.print(longArray[i]+" ");
      71.     }
      72. }

        本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評(píng)論

        發(fā)表

        請(qǐng)遵守用戶 評(píng)論公約

        類似文章 更多