首页 > 编程知识 正文

java byte转char,hex字符串转byte

时间:2023-05-04 20:00:58 阅读:127508 作者:4668

import Java.io.bytearray output stream;

公共类测试{

privatestaticstringhexstring=' 0123456789 abcdef abcdef ';

//privatestaticstringhexstring=' 0123456789 abcdef abcdef ';

//*

publicstaticvoidmain (字符串敏感招牌args )。

byte敏感招牌bytes=msg.getBytes (;

转换//hex代码

for(byteb:bytes ) {

sb.append(integer.toHEXstring ) b0x800 ).substring(1);

}

//转换后的代码为c7d7a3acc4e3bac3

msg=sb.toString (;

//再次转换为字符串

//system.out.println(msg;

}

//hex代码转换为字符串

publicstaticstringdecode (字符串字节) {

bytes=bytes.toUpperCase (;

//将每个2位的十六进制整数组装成一个字节

for(intI=0; i bytes.length (; i =2)

BAOS.write((hexstring.indexof ) bytes.charat(I ) )4| hex string.index of (bytes.charat ) I1 ) ) );

返回新字符串(baos.to bytearray );

}

}

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。