//program to convert binary no. into decimal number system

#include<stdio.h>

#include<conio.h>

#include<math.h>

void main()

{

int k=1,m=0,n,rem,decimal=0;

printf("enter binary value/number of 'n'\n");

scanf("%d",&n);

while(n!=0)

{

rem=n%10;

decimal=decimal+rem*pow(2,m);

n=n/10;

m++;

}

printf("decimal is=%d\n",decimal);

getch();

}

if binary number is 101 (base 2) then

decimal=1x2

#include<stdio.h>

#include<conio.h>

#include<math.h>

void main()

{

int k=1,m=0,n,rem,decimal=0;

printf("enter binary value/number of 'n'\n");

scanf("%d",&n);

while(n!=0)

{

rem=n%10;

decimal=decimal+rem*pow(2,m);

n=n/10;

m++;

}

printf("decimal is=%d\n",decimal);

getch();

}

**logics in mind:**if binary number is 101 (base 2) then

decimal=1x2

^{2}+0x2^{1}+1x2^{0}^{making its formlua in program}^{}^{note:}^{it does not work for long values. It can, if you declare variables as long. }
## No comments:

## Post a Comment