aboutsummaryrefslogtreecommitdiffstats
path: root/hexdump.c
diff options
context:
space:
mode:
authorroot <root@no.no.james.local>2015-09-01 11:42:26 +0100
committerroot <root@no.no.james.local>2015-09-01 11:42:26 +0100
commit68041c4710fc044c13f4107a74ae26badf611fd8 (patch)
tree7d86fa94ec98e2078f2b67c12d4386bf3e1899c1 /hexdump.c
parent7e25356deec3369773e3949fe7336d84c10834c0 (diff)
downloadnrfdfu-68041c4710fc044c13f4107a74ae26badf611fd8.tar.gz
nrfdfu-68041c4710fc044c13f4107a74ae26badf611fd8.tar.bz2
nrfdfu-68041c4710fc044c13f4107a74ae26badf611fd8.zip
works
Diffstat (limited to 'hexdump.c')
-rw-r--r--hexdump.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/hexdump.c b/hexdump.c
new file mode 100644
index 0000000..e664d3c
--- /dev/null
+++ b/hexdump.c
@@ -0,0 +1,50 @@
+#include "project.h"
+
+void
+hexdump (void *_d, int len)
+{
+ uint8_t *d = (uint8_t *) _d;
+ int i, j, k;
+ int e;
+
+ if (!d || len < 0)
+ return;
+
+ e = len + 15;
+ e &= ~15;
+
+ for (i = 0; i < e; i += 16)
+ {
+ printf (" %05x:", i);
+ for (j = 0; j < 16; ++j)
+ {
+ k = i + j;
+
+ if (k < len)
+ printf (" %02x", d[k]);
+ else
+ printf (" ");
+
+ if (j == 7)
+ printf (" ");
+ }
+
+ printf (" ");
+ for (j = 0; j < 16; ++j)
+ {
+ k = i + j;
+ if (k < len)
+ {
+ uint8_t c = d[k];
+ if (c < 33)
+ c = '.';
+ if (c > 126)
+ c = '.';
+ printf ("%c", c);
+ }
+ if (j == 7)
+ printf (" ");
+ }
+ printf ("\n");
+ }
+}