Java[Java] Hex String & Byte Array 轉換Java Hex String 與 Byte Array 互轉的程式碼片段,使用 BigInteger 類別實作 toHexString 和 fromHexString 兩個轉換方法。1 2 3 4 5 6 7 8 9 public String toHexString(byte[] in){ BigInteger temp = new BigInteger(in); return temp.toString(16); } public byte[] fromHexString(String in){ BigInteger temp = new BigInteger(in, 16); return temp.toByteArray(); } 文章參考自此