Arbitrary hexadecimal (hex to 16 hex 2) transfer coded decimal (0 to 2,147,483,647).

#include <stdio.h>
#include <string.h>

void main() {
    int res = 0, radix, i, k = 1;
    char num[32], table[] = "0123456789ABCDEF";
    printf("Please enter the value to be converted:");
    scanf("%s", &num);
    printf("Please enter the radix to be converted:");
    scanf("%d", &radix);
    for (i = strlen(num) - 1; i >= 0; i--) {
        res += (strchr(table, num[i]) - table) * k;
        k *= radix;
    }
    printf("Result:%d", res);
}
Published 139 original articles · won praise 4 · Views 930,000 +

Guess you like

Origin blog.csdn.net/qq_38490457/article/details/104739340