blob: afa1cd04108ae3228479a9cae73926eb4205283a (
plain)
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ASCII_HEXLEN 3
static void defaultHexOut(char *text) {
int i;
size_t len;
for (i = 0; i < (len = strlen(text)); i++) {
printf("0x%X%c", text[i], (i == len-1 ? '\n' : ' '));
}
}
static void dwordHexOut(char *text) {
int i;
size_t len;
for (i = 0; i < (len = strlen(text)); i++) {
printf("%s%X%s", (i % 4 == 0 ? (i == 0 ? "0x" : " 0x") : ""), text[i], (i == len-1 ? "\n" : ""));
}
}
static void strHexOut(char *text) {
int i;
size_t len;
for (i = 0; i < (len = strlen(text)); i++) {
printf("%s%X%s", (i == 0 ? "0x" : ""), text[i], (i == len-1 ? "\n" : ""));
}
}
int main(int argc, char **argv)
{
if (argc != 2) {
fprintf(stderr, "usage: %s [TEXT]\n", argv[0]);
return 1;
}
defaultHexOut(argv[1]);
dwordHexOut(argv[1]);
strHexOut(argv[1]);
return 0;
}
|