OLD | NEW |
1 #include <stdlib.h> | 1 #include <stdlib.h> |
2 #include <string.h> | 2 #include <string.h> |
3 #include <stdint.h> | 3 #include <stdint.h> |
4 | 4 |
5 static const char digits[] = | 5 static const char digits[] = |
6 » "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; | 6 "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; |
7 | 7 |
8 long a64l(const char *s) | 8 long a64l(const char* s) { |
9 { | 9 int e; |
10 » int e; | 10 uint32_t x = 0; |
11 » uint32_t x = 0; | 11 for (e = 0; e < 36 && *s; e += 6, s++) |
12 » for (e=0; e<36 && *s; e+=6, s++) | 12 x |= (strchr(digits, *s) - digits) << e; |
13 » » x |= (strchr(digits, *s)-digits)<<e; | 13 return x; |
14 » return x; | |
15 } | 14 } |
16 | 15 |
17 char *l64a(long x0) | 16 char* l64a(long x0) { |
18 { | 17 static char s[7]; |
19 » static char s[7]; | 18 char* p; |
20 » char *p; | 19 uint32_t x = x0; |
21 » uint32_t x = x0; | 20 for (p = s; x; p++, x >>= 6) |
22 » for (p=s; x; p++, x>>=6) | 21 *p = digits[x & 63]; |
23 » » *p = digits[x&63]; | 22 *p = 0; |
24 » *p = 0; | 23 return s; |
25 » return s; | |
26 } | 24 } |
OLD | NEW |