Skip to content

Instantly share code, notes, and snippets.

@Mattosx
Created April 22, 2018 10:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mattosx/5bd42e980d5fdcfd846c35c1010f85c1 to your computer and use it in GitHub Desktop.
Save Mattosx/5bd42e980d5fdcfd846c35c1010f85c1 to your computer and use it in GitHub Desktop.
bytes2HexString
int bytes2string(unsigned char *src, int srcsize, unsigned char *dst, int dstsize)
{
if (dst != NULL)
{
*dst = 0;
}
if (src == NULL || srcsize <= 0 || dst == NULL || dstsize <= srcsize * 2)
{
return 0;
}
const char szTable[] = "0123456789ABCDEF";
for(int i=0; i<srcsize; ++i)
{
*dst++ = szTable[src[i] >> 4];
*dst++ = szTable[src[i] & 0x0f];
}
*dst = 0;
return srcsize * 2;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment