//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();
}
logics in mind:
if binary number is 101 (base 2) then
decimal=1x22+0x21+1x20
making its formlua in program
note:
it does not work for long values. It can, if you declare variables as long.
#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=1x22+0x21+1x20
making its formlua in program
note:
it does not work for long values. It can, if you declare variables as long.