#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, b, i; for (i = e, c = 1, b = 0; i >= s; --i, b++) { if (d[i]) ret += c; switch (b & 3) { case 0: case 1: case 2: c <<= 1; break; default: c >>= 3; c *= 10; } } return ret; } unsigned le_bcd (uint8_t *d, unsigned s, unsigned e) { unsigned ret = 0, c, b, i; for (i = s, c = 1, b = 0; i <= e; ++i, b++) { if (d[i]) ret += c; switch (b & 3) { case 0: case 1: case 2: c <<= 1; break; default: c >>= 3; c *= 10; } } return ret; }