android字符串转换成16进制怎么转

高手们,请教一下,android字符串转换成16进制怎么转
最新回答
纸墨清香

2022-08-12 20:05:53

android
字符串
转换成
16进制
,参考如下内容:
/**
* 字符串转换成
十六进制
字符串
* @param String str 待转换的ASCII字符串
* @return String 每个Byte之间空格分隔,如: [61 6C 6B]
*/
public static String str2HexStr(String str)
{

char[] chars = "0123456789ABCDEF".toCharArray();
StringBuilder sb = new StringBuilder("");
byte[] bs = str.getBytes();
int bit;

for (int i = 0; i < bs.length; i++)
{
bit = (bs[i] & 0x0f0) >> 4;
sb.append(chars[bit]);
bit = bs[i] & 0x0f;
sb.append(chars[bit]);
sb.append(' ');
}
return sb.toString().trim();
}
风铃鹿

2020-09-21 18:32:06

String转换成16进制的方法:
public static String str2HexStr(String str)

{
char[] chars = "0123456789ABCDEF".toCharArray();
StringBuilder sb = new StringBuilder("");
byte[] bs = str.getBytes();
int bit;
for (int i = 0; i < bs.length; i++) {
bit = (bs[i] & 0x0f0) >> 4;
sb.append(chars[bit]);
bit = bs[i] & 0x0f;
sb.append(chars[bit]);
sb.append(' ');
}
return sb.toString().trim();
}

至于密钥加密得看你用什么加密方式进行加密了
陌上柳絮倾城雪

2023-07-04 07:28:15

String转换成16进制的方法:
public static String str2HexStr(String str)

{
char[] chars = "0123456789ABCDEF".toCharArray(); StringBuilder sb = new StringBuilder(""); byte[] bs = str.getBytes(); int bit; for (int i = 0; i < bs.length; i++) { bit = (bs[i] & 0x0f0) >> 4; sb.append(chars[bit]); bit = bs[i] & 0x0f; sb.append(chars[bit]); sb.append(' '); } return sb.toString().trim();
}

至于密钥加密得看你用什么加密方式进行加密了
姐独占天下

2023-02-13 08:12:58

:String strInput ="湖北武汉"; StringBuffer output = new StringBuffer(); System.out.println("\""+strInput+ "\" 的utf8编码:")