Created
April 22, 2018 10:14
-
-
Save Mattosx/5bd42e980d5fdcfd846c35c1010f85c1 to your computer and use it in GitHub Desktop.
bytes2HexString
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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