Java中字符串转为16进制表示

Java中字符串转为16进制表示

        String str = "鲸";
char[] chars = "0123456789ABCDEF".toCharArray();
StringBuilder builder = new StringBuilder("");
byte[] bs = str.getBytes();
int bit;
for (int i = 0; i < bs.length; i++) {
bit = (bs[i] & 0x0f0) >> 4;
builder.append(chars[bit]);
bit = bs[i] & 0x0f;
builder.append(chars[bit]);
builder.append(' ');
}
System.out.println(builder.toString().trim());
上一篇:DeepLearning.ai学习笔记(三)结构化机器学习项目--week2机器学习策略(2)


下一篇:java中的数据加密2 对称加密