// a6p2 example code with no error checking // #include #include #include int hex( int c) { int r = 0; c = toupper(c); if( c >= '0' && c <= '9') r = c - '0'; // ok, or use isdigit() else if( c >= 'A' && c <= 'F') r = c - 'A' + 10; // not portable return r; } int input( unsigned char x[]) { char s[BUFSIZ]; fgets( s, BUFSIZ, stdin); int len = strlen(s)/2; for( int i = len-1, j = 0; i >= 0; --i, j += 2) x[i] = 16*hex(s[j]) + hex(s[j+1]); return len; } int main( void) { unsigned char a[BUFSIZ]; int alen = input(a); for( int i = alen-1; i >= 0; --i) printf( "%02x", a[i]); putchar('\n'); }