Gostria de saber como faço para converter um valor em Hexdecimal para byte[], um hexdecimal em formato de Sring
public class HexCodec {
private static final char[] kDigits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a',
'b', 'c', 'd', 'e', 'f' };
public static byte[] hexToBytes(char[] hex) {
int length = hex.length / 2;
byte[] raw = new byte[length];
for (int i = 0; i < length; i++) {
int high = Character.digit(hex[i * 2], 16);
int low = Character.digit(hex[i * 2 + 1], 16);
int value = (high << 4) | low;
if (value > 127)
value -= 256;
raw[i] = (byte) value;
}
return raw;
}
public static byte[] hexToBytes(String hex) {
return hexToBytes(hex.toCharArray());
}
}
Fonte: http://www.java2s.com/Code/Java/Development-Class/ConverthexToBytes.htm
1o resultado do google para “java convert hexa to byte[]”.
Resolve?
Hmm… e se for assim?
String str = "68656c6c6f";
byte[] b = new BigInteger(str, 16).toByteArray();
É isso que eu quero, utilizar o recurso do JAVA para converter valores, evitando o máx. o risco de futuros erros no código.
Vlw pela ajuda