-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10473.c
More file actions
43 lines (38 loc) · 856 Bytes
/
10473.c
File metadata and controls
43 lines (38 loc) · 856 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <stdio.h>
#include <string.h>
#include <math.h>
int main(int argc, char const *argv[])
{
char in[10]={0};
int ten=0,hex=0;
while(~scanf("%s",in)){
if(in[0]=='-') break;
//printf("%c\n",in[0] );
//printf("%cin1\n",in[1] );
//printf("%dlen\n",strlen(in) );
if(in[1]=='x'){
hex=0;
for (int i = 0; i < strlen(in)-2; ++i)
{
if(in[strlen(in)-1-i]<60){ //ASCII碼大寫字母從65開始,數字57結束
hex+=(in[strlen(in)-1-i]-48)*pow(16,i);
//printf("%dnormal\n",hex );
}
else{
hex+=(in[strlen(in)-1-i]-55)*pow(16,i);
//printf("%dhex\n%dic\n%c\nc",hex,i,in[strlen(in)-1-i] );
}
}
printf("%d\n",hex );
}
else{
ten=0;
for (int i = 0; i < strlen(in); ++i){
ten+=(in[strlen(in)-1-i]-48)*pow(10,i);
}
printf("0x%X\n",ten);
}
//printf("%d\n",ten );
}
return 0;
}