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

Badboy is defined who has ALL the following properties: Does not have a girlfriend and is not married. He is not more than 23 years old. The middle name should be "Singh" The last name should have more than 4 characters. The character 'a' should appear in the last name at least two times. The name of one of his brothers should be "Ram" Write a method: boolean isBadBoy(boolean hasGirlFriend , boolean isMarried, int age , String middleName , String lastName , String[] brotherName); isHaveGirlFriend is true if the person has a girlfriend isMarried is true if the person is married age is the age of the person middleName is the middle name of the person lastName is the last name of the person brotherName is the array of the names of his brothers

1420


How can I write a function that takes a format string and a variable number of arguments?

600


What are the different types of data structures in c?

595


What standard functions are available to manipulate strings?

556


What is a function in c?

567






If errno contains a nonzero number, is there an error?

797


Can you please explain the difference between malloc() and calloc() function?

609


What is the use of linkage in c language?

611


How can I rethow can I return a sequence of random numbers which dont repeat at all?

700


What is meant by preprocessor in c?

526


What is an example of structure?

584


FILE *fp1,*fp2; fp1=fopen("one","w") fp2=fopen("one","w") fputc('A',fp1) fputc('B',fp2) fclose(fp1) fclose(fp2)} a.error b. c. d.

1192


What is the difference between exit() and _exit() function?

597


How do you print only part of a string?

606


How do you declare a variable that will hold string values?

661