some tweaks
[mkp224o.git] / hex.h
blobc85ef28cff3d4eac14ebb050fa58051503e38bba
1 #include <stdio.h>
3 static const char hext[] = "0123456789ABCDEF";
4 static void printhex(const unsigned char *z,size_t l)
6 printf("[");
7 for (size_t i = 0;i < l;++i) {
8 printf("%c%c",hext[*z >> 4],hext[*z & 0xF]);
9 ++z;
11 printf("]\n");
14 static void printbin(const unsigned char *z,size_t l)
16 printf("[");
17 for (size_t i = 0;i < l;++i) {
18 printf("%c%c%c%c%c%c%c%c",
19 hext[(*z >> 7) & 1],
20 hext[(*z >> 6) & 1],
21 hext[(*z >> 5) & 1],
22 hext[(*z >> 4) & 1],
23 hext[(*z >> 3) & 1],
24 hext[(*z >> 2) & 1],
25 hext[(*z >> 1) & 1],
26 hext[(*z ) & 1]);
27 ++z;
29 printf("]\n");