summaryrefslogtreecommitdiffstats
path: root/app/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'app/util.c')
-rw-r--r--app/util.c29
1 files changed, 10 insertions, 19 deletions
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;