Dear all:
I've created TCPsocket in linux using C++. It receives an array of unsigned characters. I need the corresponding hex values in character format.
i.e. "ABC" in hex it is "414243". Now I want to treat each of "414243" as character.
So I have done the coding as follow ( taking into cosideration that the TCP socket is established and the data is received in an unsigned character pointer m_cpSockData sized same to Buffer Size of the socket. And the number of byte read is m_iReadLen).
char* m_cHexvalue = new char[2*BufSize +1];
char *m_cCurrCharVal=new char[3];
*(m_cCurrCharVal+2)=0X00;
memset(m_cHexvalue ,0,2);
for(int count=0;count<BufSize ;count++)
{
memset(m_cCurrCharVal,0,2);
sprintf(m_cCurrCharVal,"%x",*(m_cpSockData+count));
strcat(m_cHexvalue ,m_cCurrCharVal);
}
<< moderator edit: added [code][/code] tags >>
I also have similar thing while writing back to the socket.
But this reduces the efficiency of the code..
Can any body help to provide a mechanism where efficiency can be increased.