From 971cc458aea21832a20b1b087185659d8e9ec2b3 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 19 Feb 2019 23:00:23 +0000 Subject: fix offsets --- app/util.c | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) (limited to 'app/util.c') diff --git a/app/util.c b/app/util.c index ff35288..7f05a60 100644 --- a/app/util.c +++ b/app/util.c @@ -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; -- cgit v1.2.3