Skip to content
This repository has been archived by the owner on Dec 29, 2019. It is now read-only.

Commit

Permalink
perform hex dumps
Browse files Browse the repository at this point in the history
  • Loading branch information
mburumaxwell committed Mar 7, 2016
1 parent 2b90243 commit 82b44fe
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions main.c
Expand Up @@ -32,3 +32,46 @@ int main(void) {
#endif
osSignalSet(tid_TLSThread, 0x01);
}

#include "stdio.h"
void hex_dump(FILE* f, void *addr, int len) {
int i;
unsigned char buff[17];
unsigned char *pc = (unsigned char*)addr;

if (len == 0 || len < 0) return;

// Process every byte in the data.
for (i = 0; i < len; i++) {
// Multiple of 16 means new line (with line offset).

if ((i % 16) == 0) {
// Just don't print ASCII for the zeroth line.
if (i != 0)
fprintf(f, " %s\n", buff);

// Output the offset.
fprintf(f, " %04x: ", i);
}

// Now the hex code for the specific character.
fprintf(f, " %02x", pc[i]);

// And store a printable ASCII character for later.
if ((pc[i] < 0x20) || (pc[i] > 0x7e))
buff[i % 16] = '.';
else
buff[i % 16] = pc[i];
buff[(i % 16) + 1] = '\0';
}

// Pad out last line if not exactly 16 characters.
while ((i % 16) != 0) {
fprintf(f, " ");
i++;
}

// And print the final ASCII bit.
printf (" %s\n", buff);
}

0 comments on commit 82b44fe

Please sign in to comment.