字符串转16进制和16进制转字符串

 //字符串转16进制
BOOL str2Hs(const char * str, LPSTR lpHs) 
  {
	  int i=0;
	  while (1) 
	  {
		  if (0 == str[i]) 
			  break;
		  sprintf(lpHs+i*2, "%02X", (unsigned char)str[i]);
		  i++;
	  }
	  return TRUE; 
}

//16进制转字符串
BOOL Hs2Str(const char * cHs, LPSTR lpstr) 
{ 
	int i=0, v;
	while (1) 
	{
		if (1 != sscanf( cHs+i*2,"%2x", &v)) 
			break;
		lpstr[i]=(char)v;
		i++;
	}
	lpstr[i]=0;

	return TRUE; 
}

你可能感兴趣的:(c++)