fork(2) download
  1. #include <stdio.h>
  2.  
  3. void print(unsigned x)
  4. {
  5. int i;
  6. for(i = 1; i <= 32; i++, x <<= 1)
  7. {
  8. putchar(x & 0x80000000 ? '1' : '0');
  9. if ((i & 3) == 0) putchar(' ');
  10. }
  11. }
  12.  
  13. int main(void) {
  14. const char* string = "ABcd1234";
  15. unsigned out=0;
  16. char x;
  17. while((x = *string++))
  18. {
  19. unsigned value;
  20. if (x < '0') goto invalid;
  21. if (x < '9' + 1) { value = x - '0'; goto valid; }
  22. if (x < 'A') goto invalid;
  23. if (x < 'F' + 1) { value = x - 'A' + 10; goto valid; }
  24. if (x < 'a') goto invalid;
  25. if (x < 'f' + 1) { value = x - 'a' + 10; goto valid; }
  26. goto invalid;
  27. valid:
  28. out = (out << 4) | value;
  29. }
  30. print(out);
  31. return 0;
  32. invalid: return 1;
  33. }
  34.  
Success #stdin #stdout 0s 2160KB
stdin
Standard input is empty
stdout
1010 1011 1100 1101 0001 0010 0011 0100