题解 | #十六进制转十进制#
十六进制转十进制
https://www.nowcoder.com/practice/33e148570d5c4e728116e2f861638c9c
#include <stdio.h> #include <string.h> #define N 15 int getNum(char c) { if (c >= '0' && c <= '9') return c - '0'; return (c - 'A') + 10; } char getChar(int num) { if (num >= 0 && num <= 9) return num + '0'; else return (num - 10) + 'A'; } int main() { char s[] = {'A', 'B', 'C', 'D', 'E', 'F'}; int res = 0; for (int i = 0; i < strlen(s); i ++ ) { res = res * 16 + getNum(s[i]); } printf("%15d", res); return 0; }