blob: 7f05a602297d946d3f4d7597bce946f4ab348d0d (
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
50
51
52
53
54
55
56
57
  | 
#include "project.h"
int check_parity (uint8_t *d, unsigned s, unsigned e, uint8_t p)
{
  unsigned i;
  for (i = s; i <= e; ++i)
    p ^= d[i];
  return !p;
}
unsigned bcd (uint8_t *d, unsigned s, unsigned e)
{
  unsigned ret = 0, c, i;
  for (i = e, c = 1 ; i >= s; --i) {
    if (d[i]) ret += c;
    if (c & 0x77777777)
      c <<= 1;
    else {
      c >>= 3;
      c *= 10;
    }
  }
  return ret;
}
unsigned le_bcd (uint8_t *d, unsigned s, unsigned e)
{
  unsigned ret = 0, c, i;
  for (i = s, c = 1 ; i <= e; ++i) {
    if (d[i]) ret += c;
    if (c & 0x77777777)
      c <<= 1;
    else {
      c >>= 3;
      c *= 10;
    }
  }
  return ret;
}
 
  |