re/src/fmt/ch.c

30 lines
458 B
C
Raw Normal View History

2010-11-03 11:34:14 +00:00
/**
* @file ch.c Character format functions
*
* Copyright (C) 2010 Creytiv.com
*/
#include <re_types.h>
#include <re_fmt.h>
/**
2011-03-01 11:11:08 +00:00
* Convert an ASCII hex character to binary format
2010-11-03 11:34:14 +00:00
*
2011-03-01 11:11:08 +00:00
* @param ch ASCII hex character
2010-11-03 11:34:14 +00:00
*
* @return Binary value
*/
uint8_t ch_hex(char ch)
{
if ('0' <= ch && ch <= '9')
return ch - '0';
else if ('A' <= ch && ch <= 'F')
return ch - 'A' + 10;
else if ('a' <= ch && ch <= 'f')
return ch - 'a' + 10;
return 0;
}