hex_to_bin的busybox实现

static unsigned hex_to_bin(unsigned char c)
{
 unsigned v;
 
 v = c - '0';
 if (v <= 9)
  return v;
 /* c | 0x20: letters to lower case, non-letters
  * to (potentially different) non-letters */
 v = (unsigned)(c | 0x20) - 'a';
 if (v <= 5)
  return v + 10;
 return ~0;
/* For testing:
void t(char c) { printf("'%c'(%u) %u\n", c, c, hex_to_bin(c)); }
int main() { t(0x10); t(0x20); t('0'); t('9'); t('A'); t('F'); t('a'); t('f');
t('0'-1); t('9'+1); t('A'-1); t('F'+1); t('a'-1); t('f'+1); return 0; }
*/
}

你可能感兴趣的:(hex_to_bin的busybox实现)