1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
#include<stdlib.h>
#include<stdio.h>
int main()
{
int a,i,j,cpt;
unsigned long c,e;
int tab[32] = {0};
c=0;cpt=0;i=0;
printf("Entrer le nombre à convertir en tableau de 32 bits :\n");
scanf("%d",&a);
e=a;
c=e>>1; //au lieu de c=e/2
while(c!=0)
{
tab[i]=e%2;
i++;
e=c;
c=e>>1; // au lieu de c=e/2;
}
tab[i]=e;
for(j=31;j>=0;j--)
{ if(cpt==4)
{
printf("\t");
cpt=0;
printf("%d",tab[j]);
}
else
printf("%d",tab[j]);
cpt++;
}
printf("\n");
return 0;
} |
Partager