diff options
Diffstat (limited to 'util.c')
-rw-r--r-- | util.c | 38 |
1 files changed, 38 insertions, 0 deletions
@@ -0,0 +1,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; + } + } +} + + + |