-
Notifications
You must be signed in to change notification settings - Fork 12
/
main_bcd2a.c
32 lines (27 loc) · 969 Bytes
/
main_bcd2a.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
#include <stddef.h>
void *bcd2ascii(void* dst, const void* src, size_t n);
static const unsigned char inp[] = {
0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, // 8
0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10, // 16
0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, // 24
0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10, // 32
0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, // 40
0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10, // 48
0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, // 56
0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 // 64
};
#include <stdio.h>
int main()
{
char out[sizeof inp * 2 + 1] = {0};
// expected output:
// out = { '0', '1', '2', '3', ... }
bcd2ascii(out, inp, sizeof inp);
puts(out);
for (size_t i = 1; i < sizeof inp + 1; ++i) {
__builtin_memset(out, 0, sizeof out);
bcd2ascii(out, inp, sizeof inp-i);
puts(out);
}
return 0;
}