summaryrefslogtreecommitdiffstats
path: root/util.c
blob: 8be15a4b67a34946656703ea72512a792d2a42ae (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
#include "project.h"

int set_parity (uint8_t *d, unsigned s, unsigned e)
{
  unsigned i;
  uint8_t p = 0;

  for (i = s; i <= e; ++i)
    p ^= d[i];

  return !p;
}


void  bcd_set (uint8_t *d, unsigned s, unsigned e, unsigned v)
{
  unsigned c, i, w;


  w = v % 10;

  for (i = e, c = 1 ; i >= s; --i) {

    d[i] = !! (c & w) ;

    if (c & 0x77777777)
      c <<= 1;
    else {
      c >>= 3;
      c *= 10;
      v = v / 10;
      w = v % 10;
    }
  }
}