FreeCalypso > hg > sms-coding-utils
diff libcoding/hexdigits.c @ 7:cd2d82ec5144
libcoding/hexdigits.c: import from fc-sim-tools/libutil
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 05 Aug 2023 06:32:37 +0000 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libcoding/hexdigits.c Sat Aug 05 06:32:37 2023 +0000 @@ -0,0 +1,23 @@ +/* + * This module contains elementary functions for working with hex digits. + */ + +decode_hex_digit(c) +{ + if (c >= '0' && c <= '9') + return(c - '0'); + if (c >= 'A' && c <= 'F') + return(c - 'A' + 10); + if (c >= 'a' && c <= 'f') + return(c - 'a' + 10); + return(-1); +} + +encode_hex_digit(d) + unsigned d; +{ + if (d <= 9) + return(d + '0'); + else + return(d - 10 + 'A'); +}