aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2010-03-04 10:50:32 +0100
committerHarald Welte <laforge@gnumonks.org>2010-03-04 10:50:32 +0100
commita73e2f9acb839a1f08d8bc5c7e6074c16f0cf1fe (patch)
tree46d26080f830545c24a455a1ac3aaeca64663473 /src
parentaebe08c71f4704914c2af40620d0675cf29d2639 (diff)
import bcd2char() and char2bcd() from OpenBSC
Diffstat (limited to 'src')
-rw-r--r--src/utils.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/utils.c b/src/utils.c
index 0d878c7b..2a73d397 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -30,3 +30,17 @@ int get_string_value(const struct value_string *vs, const char *str)
}
return -EINVAL;
}
+
+char bcd2char(uint8_t bcd)
+{
+ if (bcd < 0xa)
+ return '0' + bcd;
+ else
+ return 'A' + (bcd - 0xa);
+}
+
+/* only works for numbers in ascci */
+uint8_t char2bcd(char c)
+{
+ return c - 0x30;
+}