how to convert binary to decimal and decimal to binary in C
lanaguage

Answer Posted / saravana priya

#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() */

Is This Answer Correct ?    25 Yes 9 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How would you obtain the current time and difference between two times?

996


Explain pointers in c programming?

879


what is the difference between class and unio?

2118


How does selection sort work in c?

819


What is string function c?

800


how can i access hard disk address(physical address)? are we access hard disk by using far,near or huge pointer? if yes then please explain.....

1598


How can I make it pause before closing the program output window?

809


Write programs for String Reversal & Palindrome check

816


What is typedef example?

858


What is time null in c?

770


What are static variables in c?

832


What is double pointer in c?

775


How does #define work?

851


Why is C language being considered a middle level language?

862


A text file that contains declarations used by a group of functions,programs,or users a) executable file b) header file c) obj file d) .cfile

871