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 44
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
int Binary[7],x,v,z,d,e,f,g,h;
Binary[0]=x;
Binary[1]=v;
Binary[2]=z;
Binary[3]=d;
Binary[4]=e;
Binary[5]=f;
Binary[6]=g;
Binary[7]=h;
int decimal,numm0,numm1,numm2,numm3,numm4,numm5,numm6,numm7;
decimal = x*128+v*64+z*32+d*16+e*8+f*4+g*2+h*1;
printf("Binary to Decimal conversion");
printf("\n==========================\n");
printf("Please enter a 8-digit Decimal:");
scanf("%d,%d,%d,%d,%d,%d,%d,%d",&x,&v,&z,&d,&e,&f,&g,&h);
printf("Your entered value is %d,\n",x,v,z,d,e,f,g,h);
numm0=x*128;
numm1=v*64;
numm2=z*32;
numm3=d*16;
numm4=e*8;
numm5=f*4;
numm6=g*2;
numm7=h*1;
printf("The decimal value is\n(%dx128=%d)+(%dx64=%d)+(%dx32=%d)+(%dx16=%d)+(%dx8=%d)+(%dx4=%d)+(%dx2=%d)+(%dx1=%d)=%d\n",x,numm0,v,numm1,z,numm2,d,numm3,e,numm4,f,numm5,g,numm6,h,numm7,decimal);
system("pause");
return 0;
}
|