summaryrefslogtreecommitdiffstats
path: root/util.c
diff options
context:
space:
mode:
authorroot <root@no.no.james.local>2019-02-26 15:38:49 +0000
committerroot <root@no.no.james.local>2019-02-26 15:38:49 +0000
commit9ada072d5337a582e987ed57dc4816189208dea7 (patch)
tree657295fefd5ec9ec153f92ba77bd46d82b0977f8 /util.c
parent89aa56f25116fc642928f352c14fe2d485532749 (diff)
downloadgen_msf-9ada072d5337a582e987ed57dc4816189208dea7.tar.gz
gen_msf-9ada072d5337a582e987ed57dc4816189208dea7.tar.bz2
gen_msf-9ada072d5337a582e987ed57dc4816189208dea7.zip
fix bcd encoder
Diffstat (limited to 'util.c')
-rw-r--r--util.c34
1 files changed, 33 insertions, 1 deletions
diff --git a/util.c b/util.c
index 8be15a4..d8632c5 100644
--- a/util.c
+++ b/util.c
@@ -27,7 +27,6 @@ void bcd_set (uint8_t *d, unsigned s, unsigned e, unsigned v)
c <<= 1;
else {
c >>= 3;
- c *= 10;
v = v / 10;
w = v % 10;
}
@@ -35,4 +34,37 @@ void bcd_set (uint8_t *d, unsigned s, unsigned e, unsigned v)
}
+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, i;
+
+ for (i = e, c = 1 ; i >= s; --i) {
+
+ if (d[i]) ret += c;
+
+
+ if (c & 0x77777777)
+ c <<= 1;
+ else {
+ c >>= 3;
+ c *= 10;
+ }
+ }
+
+ return ret;
+}
+
+
+