当前位置: 代码迷 >> J2SE >> 16進制字符串轉換成byte數組,该怎么处理
  详细解决方案

16進制字符串轉換成byte數組,该怎么处理

热度:278   发布时间:2016-04-24 01:48:06.0
16進制字符串轉換成byte數組
String hexStr = "55587ef4f6454e35";
我要將該字符串轉換成byte類型存放在byte類型數組中如:0x55 0x58...0x4e....0x35,應如何實現,還請各位幫忙!

------解决方案--------------------
Java code
    public static byte[] hexToBytes(String hexString) {        if (hexString == null) return null;        byte[] bytes = new byte[hexString.length()/2];        for (int i=0; i<bytes.length; i++) {            bytes[i] = (byte)Integer.parseInt(hexString.substring(i*2, i*2+2), 16);                    }        return bytes;    }
------解决方案--------------------
你结贴率不高,不回答.......
------解决方案--------------------
hexStr.getbytes();
  相关解决方案