diff options
author | root <root@lab.panaceas.james.local> | 2019-02-19 23:00:23 +0000 |
---|---|---|
committer | root <root@lab.panaceas.james.local> | 2019-02-19 23:00:23 +0000 |
commit | 971cc458aea21832a20b1b087185659d8e9ec2b3 (patch) | |
tree | f0cf4843a1b71c5860392c17ccc86a963d53b4e3 /app/util.c | |
parent | 379b0ec3e5eacdde822966c84062bea41da7ae89 (diff) | |
download | clock-971cc458aea21832a20b1b087185659d8e9ec2b3.tar.gz clock-971cc458aea21832a20b1b087185659d8e9ec2b3.tar.bz2 clock-971cc458aea21832a20b1b087185659d8e9ec2b3.zip |
fix offsets
Diffstat (limited to 'app/util.c')
-rw-r--r-- | app/util.c | 29 |
1 files changed, 10 insertions, 19 deletions
@@ -13,21 +13,16 @@ int check_parity (uint8_t *d, unsigned s, unsigned e, uint8_t p) unsigned bcd (uint8_t *d, unsigned s, unsigned e) { - unsigned ret = 0, c, b, i; + unsigned ret = 0, c, i; - for (i = e, c = 1, b = 0; i >= s; --i, b++) { + for (i = e, c = 1 ; i >= s; --i) { if (d[i]) ret += c; - switch (b & 3) { - case 0: - case 1: - case 2: + if (c & 0x77777777) c <<= 1; - break; - - default: + else { c >>= 3; c *= 10; } @@ -40,24 +35,20 @@ unsigned bcd (uint8_t *d, unsigned s, unsigned e) unsigned le_bcd (uint8_t *d, unsigned s, unsigned e) { - unsigned ret = 0, c, b, i; + unsigned ret = 0, c, i; - for (i = s, c = 1, b = 0; i <= e; ++i, b++) { + for (i = s, c = 1 ; i <= e; ++i) { if (d[i]) ret += c; - - switch (b & 3) { - case 0: - case 1: - case 2: + if (c & 0x77777777) c <<= 1; - break; - - default: + else { c >>= 3; c *= 10; } + + } return ret; |