summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2017-10-27 16:52:59 +0200
committerHarald Welte <laforge@gnumonks.org>2017-10-27 16:55:16 +0200
commitfa8983d2dd2041aea528cf966bc9f39d791df3f0 (patch)
treef9bd174a0c8e2a543a10c09731f564e653992b55 /src
parentbcf9f23456b58e4c959d84bb42d325589c3669ee (diff)
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
Diffstat (limited to 'src')
-rw-r--r--src/utils.c9
1 files changed, 8 insertions, 1 deletions
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