[coreboot] [PATCH] libpayload: Convert HEX2BIN/BIN2HEX to functions, add abs() et al

Peter Stuge peter at stuge.se
Tue Apr 8 03:11:15 CEST 2008


On Tue, Apr 08, 2008 at 02:41:23AM +0200, Uwe Hermann wrote:
> +u8 bin2hex(u8 b)
> +{
> +	return "0123456789abcdef"[b & 15];
> +}

Neat. :)


> +u8 hex2bin(u8 h)
> +{
> +	return (('0' <= h && h <= '9') ? (h - '0') : \
> +	        ('a' <= h && h <= 'f') ? (h - 'a' + 10) : 0);
> +}

Might be worth mentioning in doxygen that the return value is 0 for
invalid characters.

Also might be worth clarifying that these two only work on a nibble
rather than a full byte.


//Peter




More information about the coreboot mailing list