.AN IMPLEMENTATION TO CONVERT BINARY NUMBER INTO DECIMAL..*/
#include<stdio.h>
#include<math.h>
int powi(int,int);//MAKE FUNCTION TO FIND OUT POWER//
int main()
{
int i=0,num,dec=0,a=0,len,rem;
printf("ENTER THE NUM WHICH IS TO BE CONERTED INTO DECIMAL:\n");
scanf("%d",&num);
while(num!=0)
{
rem=num%10;//TAKE REMAINDER OF NUMBER//
num=num/10;//DIVIDE NUMBER BY 10//
a=powi(2,i);//get perticular power of 2...//
printf("pow(2,%d)=%d\n",i,a);
dec=dec+ (rem * a);//dec is 0 initially ...everytime dec is added to (rem*a)means
//NUMBER IS EVERYTIME DIVIDED BY 2//
//REM IS MULTIPLIED TO POWER OF 2.....0TH IST TIME DIVIDED//1ST 2ND TIME DIVIDED//2ND 3RD TIME DIVIDED...SO ON...//
i++;//i is what power of 2 should be taken...//increments everytime for each division of number untill number becomes 0...//
}
printf("dec=%d\n",dec);//print thAT dec VALUE....WHICH IS MADE BY ALL THE ADDITION UPTO NUM!=0;;;;
return 0;
}
int powi(int a,int i)
{
int cnst=0,s=0;
cnst=a;//a IS CONSTANT ...POWER OF WHICH NUMBER IS TO BE FIND OUT;;;;
if(i==0)//AS 0TH POW(2)=1....SO IF i=0;;;;then output==1;;;;
return 1;
else
for(s=1;s<i;s++)//1 to <i value loop will be operated to get modified value as perticular power of 2..//
a=cnst*a;//const remain permanent value 2...but a contains modified value of power of perticular number in for loop each time...//2=2*1...4=2*2....8=2*4...16=8*2....32=16*2...//
return a;//returned that modified value...//..in our case power of 2...is returned..//