diff options
Diffstat (limited to 'src/common/strlib.c')
-rw-r--r-- | src/common/strlib.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/common/strlib.c b/src/common/strlib.c index 88de59cb9..93b69ab54 100644 --- a/src/common/strlib.c +++ b/src/common/strlib.c @@ -363,6 +363,28 @@ int strline(const char* str, size_t pos) return line; } +/// Produces the hexadecimal representation of the given input. +/// The output buffer must be at least count*2+1 in size. +/// Returns true on success, false on failure. +/// +/// @param output Output string +/// @param input Binary input buffer +/// @param count Number of bytes to convert +bool bin2hex(char* output, unsigned char* input, size_t count) +{ + char toHex[] = "0123456789abcdef"; + size_t i; + + for( i = 0; i < count; ++i ) + { + *output++ = toHex[(*input & 0xF0) >> 4]; + *output++ = toHex[(*input & 0x0F) >> 0]; + ++input; + } + *output = '\0'; + return true; +} + ///////////////////////////////////////////////////////////////////// |