日期:2014-05-20  浏览次数:20718 次

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();