CHAR *fnBufferHex(
unsigned long ulValue,
unsigned char ucStyle,
CHAR *ptrBuf);
ulValue is an unsigned long value to be converted to an ASCII HEX string in the output buffer pointed to by
ptrBuf.
The conversion style is defined by
ucStyle, which can be a mixture of following flags:
- WITH_LEADIN - the output string begins with the hex lead-in "0x"
- NO_LEADIN - default
- WITH_TERMINATOR (default)
- NO_TERMINATOR - the resulting string is without a NULL-terminator
- CODE_CAPITALS - the ASCILL hex output uses capital letters to display A..F
- CODE_SMALL - (default) the ASCILL hex output uses small letters to display a..f
- WITH_SPACE - insert a space at the beginning of the string
- WITH_CR_LF - '\r\n' is added at the end of the string
The length of the hexadecimal input is also included in the ucStyle parameter, with valid values of 1, 2 or 4 (the number of bytes in the value).
The function returns a pointer to the last character in the buffer (generally the NULL-terminator). This pointer allows simple
concatenation since following string fragments can be added using this pointer.
Examples
Example of converting a MAC address into a formatted hex string output
// Convert a MAC address to a string
//
extern CHAR *fnMACStr(unsigned char *ptrMAC, CHAR *cStr)
{
int i = MAC_LENGTH;
while (--i) {
cStr = fnBufferHex(*ptrMAC++, (unsigned char)(1 | NO_LEADIN | NO_TERMINATOR), cStr);
*cStr++ = MAC_DELIMITER;
}
return (fnBufferHex(*ptrMAC++, (unsigned char)(1 | NO_LEADIN | WITH_TERMINATOR), cStr));
}
Related functions
fnBufferDec();
fnDebugHex();
fnHexStrHex();
fnDecStrHex();
Please use the
µTasker forum to ask specific questions.