#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
———————————————-*/
Not Satisfied ? Just search & get the result
Related posts:
- Sample – Program to convert 2-digit octal number into binary number and print it.
- C program to check whether a given number is prime or not and output the given number with suitable message
- C program to reverse a given integer number and check whether it is a palindrome. Output the given numbers with suitable message
- C program to accept N numbers sorted in ascending order and to search for a given number using binary search. Report success or failure in the form of suitable messages
- Little About Binary and Hexidecimal Conversion
