Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- static char trad[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
- int traduccion(char c, unsigned short B) {
- for (int i = 0; i < B; i++) {
- if (trad[i] == c) return i;
- }
- return -1;
- }
- unsigned int BaseLoad(char *S, unsigned short B) {
- unsigned int valor = 0;
- int len = strlen(S) - 1;
- unsigned int mult = 1;
- for (; len >= 0; --len) {
- int aux = traduccion(S[len], B);
- if (aux == -1) return 0;
- valor += aux * mult;
- mult *= B;
- }
- return valor;
- }
- int main() {
- printf("%d\n", BaseLoad("AB124FF", 16));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement