forked from cathugger/mkp224o
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hex.h
30 lines (28 loc) · 597 Bytes
/
hex.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <stdio.h>
static const char hext[] = "0123456789ABCDEF";
static void printhex(const unsigned char *z,size_t l)
{
printf("[");
for (size_t i = 0;i < l;++i) {
printf("%c%c",hext[*z >> 4],hext[*z & 0xF]);
++z;
}
printf("]\n");
}
static void printbin(const unsigned char *z,size_t l)
{
printf("[");
for (size_t i = 0;i < l;++i) {
printf("%c%c%c%c%c%c%c%c",
hext[(*z >> 7) & 1],
hext[(*z >> 6) & 1],
hext[(*z >> 5) & 1],
hext[(*z >> 4) & 1],
hext[(*z >> 3) & 1],
hext[(*z >> 2) & 1],
hext[(*z >> 1) & 1],
hext[(*z ) & 1]);
++z;
}
printf("]\n");
}