blob: 7bf218a5d69c115d1f1987adaea53be5a390f1bc (
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
47
48
49
|
#include <stdio.h>
int
lower(int c)
{
if (c >= 'A' && c <= 'Z') {
return c + 'a' - 'A';
} else {
return c;
}
}
int
atoi(char s[])
{
int i, n;
n = 0;
for (i = 0; s[i] >= '0' && s[i] <= '9'; ++i) {
n = 10 * n + (s[i] - '0');
}
return n;
}
/* convert string of hex digits into int digits */
int
htoi(char s[])
{
int i, n;
n = 0;
for (i = 0; s[i] >= '0' && s[i] <= 'f'; ++i) {
if (s[i] >= '0' && s[i] <= '9') {
n = 16 * n + (s[i] - '0');
} else if (s[i] >= 'A' && s[i] <= 'F') {
n = 16 * n + (s[i] - 'A' + 10);
} else if (s[i] >= 'a' && s[i] <= 'f') {
n = 16 * n + (s[i] - 'a' + 10);
}
}
return n;
}
int
main()
{
printf("%d\n", htoi("1f"));
return 0;
}
|