2003-09-19 19:08:13 +00:00
|
|
|
#include "scan.h"
|
|
|
|
|
|
|
|
int scan_fromhex(unsigned char c) {
|
2014-03-14 02:15:38 +00:00
|
|
|
c=(unsigned char)(c-'0');
|
2007-10-18 11:51:17 +00:00
|
|
|
if (c<=9) return c;
|
2014-03-14 02:15:38 +00:00
|
|
|
c=(unsigned char)(c&~0x20);
|
|
|
|
c=(unsigned char)(c-('A'-'0'));
|
2007-10-18 11:51:17 +00:00
|
|
|
if (c<6) return c+10;
|
|
|
|
return -1;
|
|
|
|
/* more readable but creates worse code:
|
2003-09-19 19:08:13 +00:00
|
|
|
if (c>='0' && c<='9')
|
|
|
|
return c-'0';
|
|
|
|
else if (c>='A' && c<='F')
|
|
|
|
return c-'A'+10;
|
|
|
|
else if (c>='a' && c<='f')
|
|
|
|
return c-'a'+10;
|
|
|
|
return -1;
|
2007-10-18 11:51:17 +00:00
|
|
|
*/
|
2003-09-19 19:08:13 +00:00
|
|
|
}
|
|
|
|
|