/**
* byte配列を16進文字列に変換する
*
* @param bytes 配列
* @return 16進文字列
*/
private String byte2hex(final byte bytes[])
{
final StringBuilder retString = new StringBuilder();
for (int i = 0; i < bytes.length; ++i)
{
retString.append(String.format("%02x", bytes[i]));
}
return retString.toString();
}
/**
* 16進文字列をbyte配列に変換する
*
* @param hex 16進文字列
* @return byte配列
* @throws Exception 指定文字列の文字列長が2の倍数でない場合
*/
private byte[] hex2byte(final String hex) throws Exception {
final int valueLen = hex.length();
if (valueLen % 2 != 0)
throw new Exception("String length has to be in multiples of 2. value = " + hex);
byte[] bts = new byte[hex.length() / 2];
for (int i = 0; i < bts.length; i++) {
bts[i] = (byte) Integer.parseInt(hex.substring(2*i, 2*i+2), 16);
}
return bts;
}