FreeCalypso > hg > fc-pcsc-tools
diff libutil/hexdigits.c @ 158:3698c8192d2d
libutil: hex digit functions factored out
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 26 Feb 2021 20:41:31 +0000 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libutil/hexdigits.c Fri Feb 26 20:41:31 2021 +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'); +}