int hexCharToInt(char c) { if (c >= '0' && c <= '9') return (c - '0'); if (c >= 'A' && c <= 'F') return (c - 'A' + 10); if (c >= 'a' && c <= 'f') return (c - 'a' + 10); return 0; } char* hexstringToBytes(string s) { int sz = s.length(); char *ret = new char[sz/2]; for (int i=0 ; i>4); char s1 = str2.at(b); str.append(1,str2.at(b)); b = 0x0f & bytes[i]; str.append(1,str2.at(b)); char s2 = str2.at(b); } return str; } int main() { char s[3] ={'a','b','c'}; std::string result; result = bytestohexstring(s,strlen(s)); for(int i=0;i<3;i++) { printf("%02x", s[i]&0xFF); } printf("\n%s\n",result.data()); system("pause");}