this program is used to print Decimal number corresponding to binary number.Let us see Example: suppose binary number is 11111111 and when you enter this number in this program then you will see it will print 255 because 111111112=25510 .Now let us see coding:
Program:
#include<stdio.h>
#include<conio.h>
main()
{
long b,dec=0,j=1,rem;
clrscr();
printf("Enter Binary number: ");
scanf("%ld",&b);
while(b!=0)
{
rem=b%10;
///////////////
dec=dec+rem*j;
///////////////
j=j*2;
///////////////
b=b/10;
///////////////
}
printf("\nDecimal is %ld",dec);
getch();
}
output:
Program:
#include<stdio.h>
#include<conio.h>
main()
{
long b,dec=0,j=1,rem;
clrscr();
printf("Enter Binary number: ");
scanf("%ld",&b);
while(b!=0)
{
rem=b%10;
///////////////
dec=dec+rem*j;
///////////////
j=j*2;
///////////////
b=b/10;
///////////////
}
printf("\nDecimal is %ld",dec);
getch();
}
output: