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

difference between native and cross compilers

1904


What are multidimensional arrays?

904


Write the Program to reverse a string using pointers.

828


What is FIFO?

1209


Write a C++ program to generate 10 integer numbers between - 1000 and 1000, then store the summation of the odd positive numbers in variable call it sum_pos, then find the maximum digit in this variable regardless of its digits length.

1804


What is the use of void pointer and null pointer in c language?

892


Is it better to bitshift a value than to multiply by 2?

895


What does void main () mean?

989


What is && in c programming?

938


How can I implement sets or arrays of bits?

849


What are structural members?

821


What are examples of structures?

831


What are lookup tables in c?

785


Explain what is wrong with this program statement? Void = 10;

1030


What are the types of variables in c?

808