C PROGRAM TO CONVERT BINARY NUMBER TO DECIMAL | Indian Shout

You are here: » C PROGRAM TO CONVERT BINARY NUMBER TO DECIMAL

C PROGRAM TO CONVERT BINARY NUMBER TO DECIMAL

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

#include <stdio.h>

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

printf(“Enter a binary number(1s and 0s)\n”);
scanf(“%d”, &num);           /*maximum five digits */

bnum = num;

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

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

}             /* End of main() */

/*———————————————
Output:
Enter a binary number(1s and 0s)
10101
The Binary number is = 10101
Its decimal equivalent is =21
———————————————-*/

indianshout android app
 
 

Categories:Uncategorized;Tags: , , , , , , , , , ,

   

9 Comments to “C PROGRAM TO CONVERT BINARY NUMBER TO DECIMAL”

  1. Helen oyeleye says:

    Pls can you give me a more detailed way of converting binary to decimal am a begineer in C programming

  2. Ornee says:

    this was very helpful.thanks a lot for such a simple code.where can i find such simple codes for different problems of array?

  3. ehsanshah says:

    nice one dude
    keep uploading

  4. Anju says:

    Can i get some programs in assembly level languages, preferably programs in 8086.
    regards.

  5. sarath says:

    thank u for posting this usefull programs

  6. very import to known this program
    sharma mahendra

  7. kajal says:

    y cant v give 8 digit binary number? how can v write such type of a program with input of 8 digit binary number

  8. charutha says:

    cool dude…
    the program to convert binary to decimal is really awesome and different without using pow() function. thanks a lot

  9. Tomal says:

    Very nice and simple code. thank you. i really had a hard time while i was trying to use the
    pow() function.

Leave your comment here:

 
Sponsored links
Free Email Updates

Get more stuff like this
in your inbox

Subscribe to our mailing list and get interesting stuff and updates to your email inbox.

Sponsored Links