The problem description enters a positive hexadecimal number string that does not exceed 8 bits from the keyboard, converting it to a positive decimal number after the output.
Note: 10~15 in hexadecimal numbers are denoted by uppercase letters A, B, C, D, E, F, respectively. Sample input FFFF sample output 65535 ideas: Feel yourself the following two methods are right, but ... Don't say "cunning" ... Programme one:
#include <stdio.h>
#include <math.h>
#include <string.h>
int main () {
Char s[50];
scanf ("%s", s);
int T=strlen (s);
Long sum=0;
for (int i=0;i<t;i++) {
if (s[i]>= ' A ' && s[i]<= ' Z ')
S[i]=int (s[i]-' A ') +10+ ' 0 ';
sum+= ((s[i]-' 0 ') * (POW (16,t-1-i)));
}
printf ("%ld\n", sum);
}
Scenario Two:
#include <stdio.h>
int main () {
Char s[50];
scanf ("%s", s);
int t;
Long sum=0;
for (int i=0;s[i];i++) {
if (s[i]<= ' 9 ')
t=s[i]-' 0 ';
Else
t=s[i]-' A ' +10;
Sum=sum*16+t;
}
printf ("%ld\n", sum);
return 0;
}
C language · Hexadecimal goto Decimal