Advertisement
tomasaccini

Untitled

Jul 22nd, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.76 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. 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'};
  5.  
  6. int traduccion(char c, unsigned short B) {
  7.     for (int i = 0; i < B; i++) {
  8.         if (trad[i] == c) return i;
  9.     }
  10.     return -1;
  11. }
  12.  
  13. unsigned int BaseLoad(char *S, unsigned short B) {
  14.     unsigned int valor = 0;
  15.     int len = strlen(S) - 1;
  16.     unsigned int mult = 1;
  17.     for (; len >= 0; --len) {
  18.         int aux = traduccion(S[len], B);
  19.         if (aux == -1) return 0;
  20.         valor += aux * mult;
  21.         mult *= B;
  22.     }
  23.     return valor;
  24. }
  25.  
  26. int main() {
  27.     printf("%d\n", BaseLoad("AB124FF", 16));
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement