#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; }