Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <math.h>
- int convert(char *s){
- int i,x,p;
- i=x=0;
- p=1;
- for(i=strlen(s)-1; i>=0; i--){
- if((s[i]>='0')&&(s[i]<='9')){
- x=x+(s[i]-'0')*p;}
- else if(s[i]>='a'&&s[i]<='f'){
- x=x+(s[i]-'a'+10)*p;}
- else if(s[i]>='A'&&s[i]<='F'){
- x=x+(s[i]-'A'+10)*p;}
- p=p*16;
- }
- return x;
- }
- int main(){
- char s[10];
- scanf("%s",s);
- printf("%d\n",convert(s));
- }
Advertisement
Add Comment
Please, Sign In to add comment