-
Notifications
You must be signed in to change notification settings - Fork 0
/
io.c
51 lines (44 loc) · 1.02 KB
/
io.c
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
50
51
#include <stdio.h>
#include <ctype.h>
#include "io.h"
char scan_hex(uint8_t *d, uint32_t n) {
uint32_t i=0;
while(i<n) {
uint8_t b = 0;
while(1) {
int c = getchar();
if(c == EOF) return 0;
if(isdigit(c)) {
b |= c - '0';
break;
}
if('a' <= c && c <= 'f') {
b |= c - 'a' + 10;
break;
}
if('A' <= c && c <= 'F') {
b |= c - 'A' + 10;
break;
}
}
b <<= 4;
while(1) {
int c = getchar();
if(c == EOF) return 0;
if(isdigit(c)) {
b |= c - '0';
break;
}
if('a' <= c && c <= 'f') {
b |= c - 'a' + 10;
break;
}
if('A' <= c && c <= 'F') {
b |= c - 'A' + 10;
break;
}
}
d[i++] = b;
}
return 1;
}