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

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

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

    yeafee@夜飛郎

    it's usually better to solve problems with simplicity and finesse rather than muscle.

      BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
      33 隨筆 :: 3 文章 :: 2 評論 :: 0 Trackbacks
    ??1?public?class?TypeConvert?{
    ??2??????
    ??3?????/**
    ??4??????*?整數到字節數組的轉換
    ??5??????*/
    ??6?????public?static?byte[]?intToByte(int?number)?{
    ??7?????????
    ??8?????????int?temp?=?number;
    ??9?????????byte[]?b?=?new?byte[4];
    ?10?????????for?(int?i?=?b.length?-?1;?i?>?-1;?i--)?{
    ?11?????????????b[i]?=?new?Integer(temp?&?0xff).byteValue();?//?將最高位保存在最低位
    ?12?????????????temp?=?temp?>>?8;?//?向右移8位
    ?13?????????}
    ?14?????????return?b;
    ?15?????}
    ?16?
    ?17?????/**
    ?18??????*?字節數組到整數的轉換
    ?19??????*?@param?b
    ?20??????*?@return
    ?21??????*/
    ?22?????public?static?int?byteToInt(byte[]?b)?{
    ?23?????????int?s?=?0;
    ?24?????????for?(int?i?=?0;?i?<?3;?i++)?{
    ?25?????????????if?(b[i]?>=?0)
    ?26?????????????????s?=?s?+?b[i];
    ?27?????????????else
    ?28?
    ?29?????????????????s?=?s?+?256?+?b[i];
    ?30?????????????s?=?s?*?256;
    ?31?????????}
    ?32?????????if?(b[3]?>=?0)?//?最后一個之所以不乘,是因為可能會溢出
    ?33?????????????s?=?s?+?b[3];
    ?34?????????else
    ?35?????????????s?=?s?+?256?+?b[3];
    ?36?????????return?s;
    ?37?????}
    ?38?
    ?39?????/**
    ?40??????*?字符到字節轉換
    ?41??????*?@param?ch
    ?42??????*?@return
    ?43??????*/
    ?44?????public?static?byte[]?charToByte(char?ch)?{
    ?45?????????int?temp?=?(int)?ch;
    ?46?????????byte[]?b?=?new?byte[2];
    ?47?????????for?(int?i?=?b.length?-?1;?i?>?-1;?i--)?{
    ?48?????????????b[i]?=?new?Integer(temp?&?0xff).byteValue();?//?將最高位保存在最低位
    ?49?????????????temp?=?temp?>>?8;?//?向右移8位
    ?50?????????}
    ?51?????????return?b;
    ?52?????}
    ?53?
    ?54?????/**
    ?55??????*?字節到字符轉換
    ?56??????*?@param?b
    ?57??????*?@return
    ?58??????*/
    ?59?????public?static?char?byteToChar(byte[]?b)?{
    ?60?????????int?s?=?0;
    ?61?????????if?(b[0]?>?0)
    ?62?????????????s?+=?b[0];
    ?63?????????else
    ?64?????????????s?+=?256?+?b[0];
    ?65?????????s?*=?256;
    ?66?????????if?(b[1]?>?0)
    ?67?????????????s?+=?b[1];
    ?68?????????else
    ?69?????????????s?+=?256?+?b[1];
    ?70?????????char?ch?=?(char)?s;
    ?71?????????return?ch;
    ?72?????}
    ?73?
    ?74?????/**
    ?75??????*?浮點到字節轉換
    ?76??????*?@param?d
    ?77??????*?@return
    ?78??????*/
    ?79?????public?static?byte[]?doubleToByte(double?d)?{
    ?80?????????byte[]?b?=?new?byte[8];
    ?81?????????long?l?=?Double.doubleToLongBits(d);
    ?82?????????for?(int?i?=?0;?i?<?b.length;?i++)?{
    ?83?????????????b[i]?=?new?Long(l).byteValue();
    ?84?????????????l?=?l?>>?8;
    ?85?
    ?86?????????}
    ?87?????????return?b;
    ?88?????}
    ?89?
    ?90?????/**
    ?91??????*?字節到浮點轉換
    ?92??????*?@param?b
    ?93??????*?@return
    ?94??????*/
    ?95?????public?static?double?byteToDouble(byte[]?b)?{
    ?96?????????long?l;
    ?97?
    ?98?????????l?=?b[0];
    ?99?????????l?&=?0xff;
    100?????????l?|=?((long)?b[1]?<<?8);
    101?????????l?&=?0xffff;
    102?????????l?|=?((long)?b[2]?<<?16);
    103?????????l?&=?0xffffff;
    104?????????l?|=?((long)?b[3]?<<?24);
    105?????????l?&=?0xffffffffl;
    106?????????l?|=?((long)?b[4]?<<?32);
    107?????????l?&=?0xffffffffffl;
    108?
    109?????????l?|=?((long)?b[5]?<<?40);
    110?????????l?&=?0xffffffffffffl;
    111?????????l?|=?((long)?b[6]?<<?48);
    112?
    113?????????l?|=?((long)?b[7]?<<?56);
    114?????????return?Double.longBitsToDouble(l);
    115?????}
    116?}
    posted on 2007-04-16 16:32 @yeafee 閱讀(434) 評論(0)  編輯  收藏 所屬分類: 程序語言
    主站蜘蛛池模板: 一级特黄录像视频免费| 97人妻无码一区二区精品免费| 亚洲精品二区国产综合野狼| 91精品国产免费入口| 亚洲乱妇熟女爽到高潮的片| 亚洲综合精品网站在线观看| 亚洲人成在线免费观看| 国产亚洲综合视频| 亚洲av片劲爆在线观看| 成人免费a级毛片| 国内精品免费久久影院| 亚洲a∨无码男人的天堂| 久久精品亚洲福利| 夜夜爽免费888视频| 丝袜足液精子免费视频| 亚洲私人无码综合久久网| 国产亚洲无线码一区二区| 最新猫咪www免费人成| 91精品全国免费观看青青| 亚洲色大成网站www久久九| 亚洲AV无码久久寂寞少妇| 精品免费国产一区二区| 无码少妇精品一区二区免费动态 | 国产亚洲精品免费| 亚洲av永久无码精品国产精品 | 97se亚洲综合在线| 久久亚洲国产精品123区| 最近中文字幕无吗免费高清| 久久久久久久岛国免费播放 | 女人被弄到高潮的免费视频| 免费在线看黄的网站| 污视频网站免费观看| 亚洲色无码专区一区| 亚洲综合综合在线| 亚洲乱码中文字幕综合| 日韩在线看片免费人成视频播放| 精品一区二区三区免费毛片爱| 中文字幕在线视频免费| 五月天婷婷免费视频| 黄床大片30分钟免费看| 亚洲人精品亚洲人成在线|