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

Why is it important to memset a variable, immediately after allocating memory to it ?

1550


Why do we use static in c?

629


What is #include cctype?

575


Differentiate between a for loop and a while loop? What are it uses?

663


Are there any problems with performing mathematical operations on different variable types?

569






how to construct a simulator keeping the logical boolean gates in c

1722


what is the c source code for the below output? 10 10 10 10 10 10 10 10 10 10 9 9 7 6 6 6 6 6 6 9 7 5 9 7 3 2 2 5 9 7 3 1 5 9 7 3 5 9 7 4 4 4 4 5 9 7 8 8 8 8 8 8 8 8 9

1426


What is substring in c?

634


What is file in c preprocessor?

648


Explain what is wrong with this statement? Myname = ?robin?;

992


Did c have any year 2000 problems?

649


Should a function contain a return statement if it does not return a value?

592


Define the scope of static variables.

602


What does struct node * mean?

595


difference between native and cross compilers

1669