Olá pessoal, dessa vez venho aqui com um conversor de Hexadecimal pra Decimal.
Obrigado,
Código:
#include<stdio.h> #include<stdlib.h> #include<conio.h> int getHex (char c) { char hex2[] = "123456789ABCDEF"; int i = 0; while(hex2[i] != c) { i++; } i += 1; return i; } void strcopy (char *str1, char *str2) { while(*str2) { *str1 = *str2; str1++; str2++; } *str1 = '\0'; } int strl(char *str) { int i = 0; while(*str) { str++; i++; } return i; } int eleva (int i) { int i2 = 1; int anterior = 16; if(i == 0) { return 1; } while(i2 < i) { anterior = 16 * anterior; i2 ++ ; } return anterior; } void gh(void) { system("cls"); int i = 0; char *banner[] = {"##################payl04d######################\n\n", "Feito por #payL04d em especial ao GH ( Guia do Hacker ) !\n\n", "##################payL04d######################\n\n"}; while (i < 3) { printf("%s",banner[i]); i ++ ; } } int main(int argc, char *argv[]) { char *hex; int i = strl(argv[1]); int i2; int i3; int i4; int i5 = 0; int i6 = 0; gh(); hex = malloc((i + 1) * sizeof(char)); strcopy(hex, argv[1]); i2 = i; i -= 1; while(i2 > 0) { i3 = getHex (hex[i6]); i4 = i3 * (eleva(i) ); // printf("i : %d -->",eleva(i)); i5 += i4; //printf("%d\n",i5); i -- ; i2 -- ; i6 ++ ; } printf("\n\nEM DECIMAL -- > %d \n",i5); return 0; }
Comment