java-將整數轉成高低位元組的十六進位制字串
阿新 • • 發佈:2022-03-07
/** * 位元組流排序低位元組在前高位元組在後 * @param count * @return */ public static String Lowhigh(Integer count){ // 分別取出int的高位元組跟低位元組 int big = (count & 0xFF00) >> 8; int little = count & 0xFF; String str_big = Integer.toHexString(big); if (str_big.length()<2){ str_big = "0"+str_big; } String str_little= Integer.toHexString(little); if(str_little.length()<2){ str_little = "0"+str_little; } String xString = str_little+str_big; return xString.toUpperCase(); //轉大寫 } /** * 位元組流排序高位元組在前低位元組在後 * @param count * @return */ public static String highLow(Integer count){ // 分別取出int的高位元組跟低位元組 intbig = (count & 0xFF00) >> 8; int little = count & 0xFF; String str_big = Integer.toHexString(big); if (str_big.length()<2){ str_big = "0"+str_big; } String str_little = Integer.toHexString(little); if(str_little.length()<2){ str_little = "0"+str_little; } String xString= str_big+str_little; return xString.toUpperCase(); //轉大寫 }