]> git.neil.brown.name Git - freerunner.git/blob - lib/decode-long-sms.c
Lots of random updates
[freerunner.git] / lib / decode-long-sms.c
1
2 #include <stdio.h>
3 main(int argc, char *argv[])
4 {
5
6         int pos = 0;
7         char *c;
8         int carry = 0;
9
10         for (c = argv[1]; *c; c+= 2) {
11                 int b;
12                 char c1, c2;
13                 c1 = c[0]; c2 = c[1];
14                 if (c1 > '9')
15                         c1 = 10 + (c1-'A');
16                 else
17                         c1 = c1 - '0';
18
19                 if (c2 > '9')
20                         c2 = 10 + (c2-'A');
21                 else
22                         c2 = c2 - '0';
23
24                 b = c1*16 + c2;
25
26                 if (pos == 0) {
27                         if (carry) {
28                                 printf("%c", carry + ((b&1) << 6));
29                                 carry = 0;
30                         }
31                         b = b >> 1;
32                 } else {
33                         b = (b << (pos-1)) | carry;
34                         carry = (b & 0xff80) >> 7;
35                         b &=  0x7f;
36                 }
37                 printf("%c", b);
38                 pos++;
39                 if (pos == 7)
40                         pos = 0;
41         }
42         printf("\n");
43         exit(0);
44 }
45