Created
December 14, 2021 03:44
-
-
Save fishBone000/b9476f87cd75590b46575d5850a62fc9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
#include<stdlib.h> | |
#define MAX 4096 | |
int h2d(char *p){ | |
int result = 0; | |
for(int i = 1; i > -1; i--){ | |
if(*p >= '0' && *p <= '9') | |
result += (*p - '0')*(i?16:1); | |
else if(*p >= 'a' && *p <= 'f') | |
result += (*p - 'a'+10)*(i?16:1); | |
else if(*p >= 'A' && *p <= 'F') | |
result += (*p - 'A'+10)*(i?16:1); | |
p += 1; | |
} | |
return result; | |
} | |
int main(){ | |
char *line = (char*)calloc(MAX, 1); | |
fgets(line, MAX, stdin); | |
for(int i = 0; line[i] != '\0'; i++){ | |
if(line[i] == '0'){ | |
i++; | |
if(line[i] == 'x'){ | |
i++; | |
fprintf(stderr, "%d ", h2d(line+i)); | |
i++; | |
} | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment