Created
October 3, 2018 21:06
-
-
Save esutton/e0dcd2b2318e64d0755803899a4fc9dc to your computer and use it in GitHub Desktop.
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
/// Debug dump bytes in hexadecimal format 16-bytes per row | |
/// | |
/// \param source | |
/// \param length | |
/// | |
/// Example Output: | |
/// \code | |
/// ------------------------ | |
/// 0000 bd 7a 32 13 08 1c 1e d9 - c9 48 48 0b 5f 23 1a f5 | |
/// 0010 72 3d 8f 7a e6 2c 07 e4 - 6e 45 79 0f cb 18 13 6f | |
/// ------------------------ | |
/// \endcode | |
void debugDumpHexBytes(const char* source, int length) | |
{ | |
printf("------------------------\n"); | |
int offset = 0; | |
int row = 0; | |
char line[256]; | |
while(length > offset ) | |
{ | |
sprintf(line, "%04x ", offset); | |
for(int i = 0; i < 16; ++i) | |
{ | |
if(8 == i) | |
{ | |
strcat(line, " - "); | |
} | |
uint8_t value = source[offset++]; | |
char valueString[8]; | |
sprintf(valueString, "%02x ", value); | |
strcat(line, valueString); | |
if(length == offset) | |
{ | |
break; | |
} | |
} | |
printf("%s\n", line); | |
++row; | |
} | |
printf("........................\n"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment