utils.c 362 B

1234567891011121314151617181920
  1. int hex2bin( const char *s )
  2. {
  3. int ret=0;
  4. int i;
  5. for( i=0; i<2; i++ )
  6. {
  7. char c = *s++;
  8. int n=0;
  9. if( '0'<=c && c<='9' )
  10. n = c-'0';
  11. else if( 'a'<=c && c<='f' )
  12. n = 10 + c-'a';
  13. else if( 'A'<=c && c<='F' )
  14. n = 10 + c-'A';
  15. ret = n + ret*16;
  16. }
  17. return ret;
  18. }