Binary To Decimal Conversion in C

C Language

C Programs

Binary To Decimal Conversion in C

/* Write a C program to convert the given binary number into its equivalent decimal */

#include

void main()
{
int num, bnum, dec = 0, base = 1, rem ;

printf(“Enter the binary number(1s and 0s)n”);
scanf(“%d”, &num); /*Enter maximum five digits or use long int*/

bnum = num;

while( num > 0)
{
rem = num % 10;
dec = dec + rem * base;
num = num / 10 ;
base = base * 2;
}

printf(“The Binary number is = %dn”, bnum);
printf(“Its decimal equivalent is =%dn”, dec);

} /* End of main() */

/*—————————————————
Outpput
Enter the binary number(1s and 0s)
1010
The Binary number is = 1010
Its decimal equivalent is =10
—————————————————-*/

Share

No related posts.

Subscribe / Share

sriramraj tagged this post with: C language, C programs Read 162 articles by

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Like us in Google +