move Text hex to Encoder/Decoder

This commit is contained in:
Timi
2026-01-04 15:26:45 +08:00
parent 42f0212a40
commit 3153afad5a
4 changed files with 57 additions and 61 deletions

View File

@ -159,4 +159,20 @@ public class Encoder {
throw new TimiException(TimiCode.ERROR, e.getMessage());
}
}
/**
* 字节数据转 16 进制字符串
*
* @param bytes 字节数据
* @return 16 进制字符串
*/
public static String hex(byte[] bytes) {
final int l = bytes.length;
final char[] c = new char[l << 1];
for (int i = 0, j = 0; i < l; i++) {
c[j++] = Text.HEX_DIGITS_LOWER[(0xF0 & bytes[i]) >>> 4];
c[j++] = Text.HEX_DIGITS_LOWER[0x0F & bytes[i]];
}
return new String(c);
}
}