fork download
  1. #include <stdio.h>
  2. #include <stdint.h>
  3.  
  4. uint32_t hexChars[8] = {0};
  5.  
  6. uint32_t isHex(uint8_t ch)
  7. {
  8. return hexChars[ch >> 5] & (1 << (ch & 0x1F));
  9. }
  10.  
  11. void setBits(char *s)
  12. {
  13. while (*s)
  14. {
  15. hexChars[(*s) >> 5] |= (1 << ((*s) & 0x1F));
  16. s++;
  17. }
  18. }
  19.  
  20. int main(void) {
  21. int i;
  22. uint8_t test[] = "A test for hex characters 0123456789ABCDEFabcdef";
  23. setBits("0123456789ABCDEFabcdef");
  24.  
  25. for (i = 0; i < 8; ++i)
  26. printf("%08x, ", hexChars[i]);
  27.  
  28. for (i = 0; i < strlen(test); ++i)
  29. {
  30. if (isHex(test[i]))
  31. printf("%c is a hex character\n", test[i]);
  32. else
  33. printf("%c is NOT a hex character\n", test[i]);
  34. }
  35. return 0;
  36. }
  37.  
Success #stdin #stdout 0s 5636KB
stdin
Standard input is empty
stdout
00000000, 03ff0000, 0000007e, 0000007e, 00000000, 00000000, 00000000, 00000000, A is a hex character
  is NOT a hex character
t is NOT a hex character
e is a hex character
s is NOT a hex character
t is NOT a hex character
  is NOT a hex character
f is a hex character
o is NOT a hex character
r is NOT a hex character
  is NOT a hex character
h is NOT a hex character
e is a hex character
x is NOT a hex character
  is NOT a hex character
c is a hex character
h is NOT a hex character
a is a hex character
r is NOT a hex character
a is a hex character
c is a hex character
t is NOT a hex character
e is a hex character
r is NOT a hex character
s is NOT a hex character
  is NOT a hex character
0 is a hex character
1 is a hex character
2 is a hex character
3 is a hex character
4 is a hex character
5 is a hex character
6 is a hex character
7 is a hex character
8 is a hex character
9 is a hex character
A is a hex character
B is a hex character
C is a hex character
D is a hex character
E is a hex character
F is a hex character
a is a hex character
b is a hex character
c is a hex character
d is a hex character
e is a hex character
f is a hex character