发布网友 发布时间:2022-04-29 18:25
共3个回答
热心网友 时间:2022-06-19 00:55
staticintstr_to_hex(char*string,unsignedchar*cbuf,intlen)
{
BYTEhigh,low;
intidx,ii=0;
for(idx=0;idx<len;idx+=2)
{
high=string[idx];
low=string[idx+1];
if(high>='0'&&high<='9')
high=high-'0';
elseif(high>='A'&&high<='F')
high=high-'A'+10;
elseif(high>='a'&&high<='f')
high=high-'a'+10;
else
return-1;
if(low>='0'&&low<='9')
low=low-'0';
elseif(low>='A'&&low<='F')
low=low-'A'+10;
elseif(low>='a'&&low<='f')
low=low-'a'+10;
else
return-1;
cbuf[ii++]=high<<4|low;
}
return0;
}
/****************************************************************************
函数名称:hex_to_str
函数功能:十六进制转字符串
输入参数:ptr字符串buf十六进制len十六进制字符串的长度。
输出参数:无
*****************************************************************************/
staticvoidhex_to_str(char*ptr,unsignedchar*buf,intlen)
{
for(inti=0;i<len;i++)
{
sprintf(ptr,"%02x",buf[i]);
ptr+=2;
}
}
扩展资料
byte数组转十六进制字符串
publicstaticStringbyteArraytoHexString(byte[]b){
intiLen=b.length;
StringBuffersb=newStringBuffer(iLen*2);
for(inti=0;i<iLen;i++){
intintTmp=b[i];
while(intTmp<0){
intTmp=intTmp+256;
}
if(intTmp<16){
sb.append("0");
}
sb.append(Integer.toString(intTmp,16));
}
returnsb.toString().toUpperCase();
}
热心网友 时间:2022-06-19 00:55
#typedef unsinged char BYTE;追答#include
std::string hex_to_str(const std::vector& vec)
{
std::ostringstream oss;
oss << std::setw(2) << std::setfill('0') << std::hex;
for (auto iter = vec.begin(); iter != vec.end(); ++iter) {
oss << *iter;
}
return oss.str();
}
热心网友 时间:2022-06-19 00:56
#include <stdio.h>