view libutil/hexdigits.c @ 98:2972f00622c7

scripts/fcsim1-defprog: clear the upper bits of the mystery byte following Grcard's official "personalization" script
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 05 May 2021 04:15:15 +0000
parents 34bbb0585cab
children
line wrap: on
line source

/*
 * 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');
}