[PATCH] libosmocore[master]: osmo_char2bcd(): Implment hex digits a-f and A-F

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Harald Welte gerrit-no-reply at lists.osmocom.org
Fri Oct 27 15:20:38 UTC 2017


Review at  https://gerrit.osmocom.org/4447

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
---
M src/utils.c
1 file changed, 8 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/47/4447/1

diff --git a/src/utils.c b/src/utils.c
index f5894d8..a62f5e9 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -117,7 +117,14 @@
  */
 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

-- 
To view, visit https://gerrit.osmocom.org/4447
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I7bbcc6de08024567ab64765c12d7de71df787a7a
Gerrit-PatchSet: 1
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Harald Welte <laforge at gnumonks.org>



More information about the gerrit-log mailing list