- int length, i, count= 0;
- char* start = source;
- char x;
-
- length = strlen(source);
- // process 4 bits (1 hex digit) at a time
- while(length--)
- {
- x= *(source++);
- // capitalize
- if (x >= 'a' && x <= 'f')
- x -= 32;
- // convert to numeric value
- if (x >= '0' && x <= '9')
- x -= '0';
- else if (x >= 'A' && x <= 'F')
- x -= 'A' - 10;
- else {
- printf("Discovered unknown character %c %d at idx %tu of %s\n", x, x, source - start, start);
- return 0;
- }
- // output
- for(i= 0 ; i < 4 ; ++i, ++count)
- *(target++)= (x >> (3 - i)) & 1;
- }
-
- return count;
+ int length, i, count= 0;
+ char* start = source;
+ char x;
+
+ length = strlen(source);
+ // process 4 bits (1 hex digit) at a time
+ while(length--)
+ {
+ x= *(source++);
+ // capitalize
+ if (x >= 'a' && x <= 'f')
+ x -= 32;
+ // convert to numeric value
+ if (x >= '0' && x <= '9')
+ x -= '0';
+ else if (x >= 'A' && x <= 'F')
+ x -= 'A' - 10;
+ else {
+ printf("Discovered unknown character %c %d at idx %tu of %s\n", x, x, source - start, start);
+ return 0;
+ }
+ // output
+ for(i= 0 ; i < 4 ; ++i, ++count)
+ *(target++)= (x >> (3 - i)) & 1;
+ }
+
+ return count;