Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- int bitToNombre(int n, int tab[n])
- {
- int retour = 0;
- int j = 0;
- for(int i = n-1 ; i >= 0 ; i--)
- {
- if(tab[i] == 1)
- {
- retour = (int) retour + pow(2,j);
- }
- j++;
- }
- return retour;
- }
- void reverse(int n, int tab[n])
- {
- int copie[n];
- int j = 0;
- for(int i = n-1; i >=0; i--)
- {
- copie[i] = tab[j];
- j++;
- }
- for(int i = 0; i < n; i++)
- {
- tab[i] = copie[i];
- }
- }
- char affichHexa(int n)
- {
- char retour;
- if(n >= 10)
- //printf("%c",'a' + n%10);
- retour = 'a' + (char) n%10;
- else
- //printf("%d",n);
- retour = (char) n + '0';
- return retour;
- }
- void remplir(int n, int tab[n], int i)
- {
- for(int k = i; k < n; k++)
- tab[k] = 0;
- }
- void afficherTab(int n, int tab[n])
- {
- printf("\n");
- for(int i = 0; i < n; i++)
- {
- printf("%d ",tab[i]);
- }
- }
- int main()
- {
- char T[16];
- int tabB[4];
- for(int z = 0; z < 4; z++)
- tabB[z] = 0;
- fgets(T, 16, stdin);
- int fin = strlen(T)-1;
- int j = 0;
- printf("0x");
- int nonFini = 0;
- int compteur = 0;
- char reponse[16];
- reponse[0] = '\0';
- for(int i = fin; i >= 2; i--)
- {
- int chiffre = T[i] - '0';
- //printf("chiffre : %d\n",chiffre);
- if(j <= 2)
- {
- tabB[j] = chiffre;
- j++;
- if(i == 2)
- nonFini = 1;
- }
- else if(j == 3)
- {
- tabB[j] = chiffre;
- j = 0;
- reverse(4,tabB);
- int reponse = bitToNombre(4,tabB);
- //reponse[compteur] =
- printf("%c",affichHexa(reponse));
- for(int z = 0; z < 4; z++)
- tabB[z] = 0;
- compteur++;
- }
- }
- if(nonFini == 1)
- {
- //afficherTab(4,tabB);
- reverse(4,tabB);
- int reponse = bitToNombre(4,tabB);
- //printf("\nreponse : %d ",reponse);
- //printf("ici\n");
- affichHexa(reponse);
- }
- //printf("compteur :%d\n",compteur);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement