Hexadecimal -> file (binary)
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 char bytesToHex(byte raw) {
int length = raw.length;
char hex = new char;
for (int i = 0; i < length; i++) {
int value = (raw* + 256) % 256;
int highIndex = value >> 4;
int lowIndex = value & 0x0f;
hex = kDigits;
hex = kDigits;
}
return hex;
}
public static byte hexToBytes(char hex) {
int length = hex.length / 2;
byte raw = new byte;
for (int i = 0; i < length; i++) {
int high = Character.digit(hex, 16);
int low = Character.digit(hex, 16);
int value = (high << 4) | low;
if (value > 127)
value -= 256;
raw* = (byte) value;
}
return raw;
}
public static byte hexToBytes(String hex) {
return hexToBytes(hex.toCharArray());
}
}
在线转换工具: http://tomeko.net/online_tools/hex_to_file.php?lang=en