C > calcule hexadicemal

Titrecalcule hexadicemal
Postée le03-01-2011
Affichée147
Mini-lien
Description

converte hex to dec

EtatInconnu. Inconnu.
Code d'insertion
Options
Afficher les numéros de lignes  Mettre la source en plein ecran  Selectionner la source  Partager sur Facebook 
Téléchargement Telecharger en format txt  Telecharger en format pdf  Telecharger en format c
Plein ecran
#include <stdio.h>
#include <math.h>

int main()
{
    int t[32];
    char c=' ';
    int i=0,j,n=0;
    while (c!='\n')
    {
        scanf("%c",&c);
        if (c!='\n' && c>= '0' && c<='9')
        {
            t[i]=((int) (((char) c)))-48;
            i++;
        }
        else if (c!='\n' && ((c>= 'A' && c<='F') || (c>= 'a' && c<='f')))
        {
                 if(c>= 'A' && c<='F')
                 {
                     t[i]=((int) (((char) c)))-55;
                     i++;
                 }
                 else
                 {
                     t[i]=((int) (((char) c)))-87;
                     i++;
                 }
        }
    }
    for(j=0;j<i;j++)
    {
        n = n + t[j]*pow(16,i-j-1);
    }
    printf("%d",n);
    return 0;
}