<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    codefans

    導航

    <2005年11月>
    303112345
    6789101112
    13141516171819
    20212223242526
    27282930123
    45678910

    統計

    常用鏈接

    留言簿(2)

    隨筆分類

    隨筆檔案

    文章分類

    文章檔案

    程序設計鏈接

    搜索

    最新評論

    閱讀排行榜

    評論排行榜

    int、char、double與byte相互轉換的程序

    轉載  http://www.matrix.org.cn/thread.shtml?forum_id=19&view_id=919
    int、char、double與byte相互轉換的程序
    //整數到字節數組的轉換
      public static byte[] intToByte(int number) {
        int temp = number;
        byte[] b=new byte[4];
        for (int i=b.length-1;i>-1;i--){
          b[i] = new Integer(temp&0xff).byteValue();      //將最高位保存在最低位
          temp = temp >> 8;       //向右移8位
        }
        return b;
      }

      //字節數組到整數的轉換
      public static int byteToInt(byte[] b) {
        int s = 0;
        for (int i = 0; i < 3; i++) {
          if (b[i] >= 0)
            s = s + b[i];
          else


            s = s + 256 + b[i];
          s = s * 256;
        }
        if (b[3] >= 0)       //最后一個之所以不乘,是因為可能會溢出
          s = s + b[3];
        else
          s = s + 256 + b[3];
        return s;
      }

      //字符到字節轉換
      public static byte[] charToByte(char ch){
        int temp=(int)ch;
        byte[] b=new byte[2];
        for (int i=b.length-1;i>-1;i--){
          b[i] = new Integer(temp&0xff).byteValue();      //將最高位保存在最低位
          temp = temp >> 8;       //向右移8位
        }
        return b;
      }

      //字節到字符轉換


      public static char byteToChar(byte[] b){
        int s=0;
        if(b[0]>0)
          s+=b[0];
        else
          s+=256+b[0];
        s*=256;
        if(b[1]>0)
          s+=b[1];
        else
          s+=256+b[1];
        char ch=(char)s;
        return ch;
      }

      //浮點到字節轉換
      public static byte[] doubleToByte(double d){
        byte[] b=new byte[8];
        long l=Double.doubleToLongBits(d);
        for(int i=0;i<b.length;i++){
          b[i]=new Long(l).byteValue();
          l=l>>8;


        }
        return b;
      }

      //字節到浮點轉換
      public static double byteToDouble(byte[] b){
        long l;

        l=b[0];
        l&=0xff;
        l|=((long)b[1]<<8);
        l&=0xffff;
        l|=((long)b[2]<<16);
        l&=0xffffff;
        l|=((long)b[3]<<24);
        l&=0xffffffffl;
        l|=((long)b[4]<<32);
        l&=0xffffffffffl;

        l|=((long)b[5]<<40);
        l&=0xffffffffffffl;
        l|=((long)b[6]<<48);


        l|=((long)b[7]<<56);
        return Double.longBitsToDouble(l);
      }

    --

    posted on 2005-11-25 12:42 春雷的博客 閱讀(926) 評論(0)  編輯  收藏 所屬分類: 技術

    主站蜘蛛池模板: 91黑丝国产线观看免费| 一区二区三区观看免费中文视频在线播放 | 亚洲欧洲日产国码二区首页| 国精产品一区一区三区免费视频 | 国产嫩草影院精品免费网址| 亚洲欧美黑人猛交群| 女性无套免费网站在线看| 亚洲午夜精品一区二区麻豆| 午夜神器成在线人成在线人免费| 亚洲精品乱码久久久久久V| 亚洲综合精品香蕉久久网| 亚洲精品国产专区91在线| 日韩在线观看视频免费| 美女网站免费福利视频| 中文字幕精品亚洲无线码一区应用 | 亚洲а∨天堂久久精品| 精品国产呦系列在线观看免费| 中文字幕亚洲专区| 亚洲欧美国产日韩av野草社区| 国产高清免费在线| h在线看免费视频网站男男| 精品国产_亚洲人成在线高清 | 最近中文字幕无吗免费高清| 亚洲gay片在线gv网站| 亚洲国产成人久久一区久久 | 最刺激黄a大片免费网站| 亚洲男人第一无码aⅴ网站| 在线观看特色大片免费网站| 久久久久亚洲AV成人片| A国产一区二区免费入口| 中文字幕亚洲第一在线| 精品国产免费观看一区| www成人免费视频| 免费v片在线观看| 在线看片免费人成视频播| 国产成人精品日本亚洲18图| 亚洲精品偷拍视频免费观看 | 人妻仑乱A级毛片免费看| 亚洲高清在线视频| a在线观看免费视频| 国产成人精品日本亚洲专|