From fa8983d2dd2041aea528cf966bc9f39d791df3f0 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Fri, 27 Oct 2017 16:52:59 +0200 Subject: osmo_char2bcd(): Implment hex digits a-f and A-F osmo_bcd2char() has always supported both decimal and hex. However, osmo_char2bcd() use to only implement decimal digits. With this patch, it also suppots conversion of hex characters from ASCII to BCD. This would be relevant in cases where somebdoy would want to use 'code 11', 'code 12' or 'ST' signals in any addresses (SCCP GT e.g.) Change-Id: I7bbcc6de08024567ab64765c12d7de71df787a7a --- src/utils.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/utils.c b/src/utils.c index f5894d89..a62f5e97 100644 --- a/src/utils.c +++ b/src/utils.c @@ -117,7 +117,14 @@ char osmo_bcd2char(uint8_t bcd) */ uint8_t osmo_char2bcd(char c) { - return c - 0x30; + if (c >= '0' && c <= '9') + return c - 0x30; + else if (c >= 'A' && c <= 'F') + return 0xa + (c - 'A'); + else if (c >= 'a' && c <= 'f') + return 0xa + (c - 'a'); + else + return 0; } /*! Parse a string containing hexadecimal digits -- cgit v1.2.3