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

Answers were Sorted based on User's Feedback



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

Answer / rahul

[decimal to binary]
#include<stdio.h>
#include<conio.h>
void main()
{
int dec,bin,a[100],i=0,r,j;
printf("enter the decimal number: ");
scanf("%d",&dec);
while(dec>0)
{
r=dec%2;
dec=dec/2;
a[i]=r;
i++;
}
printf("the equivalant binary numberis: ");
for(j=i-1;j>=0;j--)
printf("%d",a[j]);
getch()
}

Is This Answer Correct ?    72 Yes 32 No

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

Answer / 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

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

Answer / fazlur rahaman naik

u can use bitwise operators and some logical thinking.

Is This Answer Correct ?    26 Yes 15 No

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

Answer / ruchi

#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
{
int n,r,s=0,i=0;
printf("\nEnter the decimal number ");
scanf("%d",&n);
while(n>0)
{
r=n%2;
n=n/2;
s=s+r*pow(10,i++);
}
printf("\nThe binary equivalent is ");
printf("%d",s);
getch();
}

Is This Answer Correct ?    27 Yes 17 No

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

Answer / sheela

#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
{
int n,r,s=0,i=0;
printf("\nEnter the binary number ");
scanf("%d",&n);
while(n>0)
{
r=n%10;
n=n/10;
s=s+r*pow(2,i++);
}
printf("\nThe binary equivalent is ");
printf("%d",s);
getch();
}

Is This Answer Correct ?    10 Yes 2 No

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

Answer / rahul

//it is to convert Binary to decimal;


#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
long int a[20],i,n,count=0,b[20],c[20],sum=0;
printf("ENter the number in binary form=\t");
scanf("%ld",&n); // Get a binary number
from the user
for (i=0;n>=1;i++)
{
a[i]=n%10;
n=n/10; // Loop To reverse the number And put
all reversed numbers in arry a[i]
count=count + 1; // count to count the number of times
this loop runs
}
for (i=0;i<=count-1;i++) // count -1 condition is used to
run the loop till the previous loop run
{
b[i]=pow(2,i); // This is to raise the power of 2 to no
of times previous loop runned.
}
for (i=0;i<=count-1;i++)
{
c[i]=a[i] * b[i]; // Multiply a[i] or reveresed binary
no with b[i] or increasing pow of 2 to count-1
sum=sum +c[i]; // it is to add the c[i] elements with
each other n put into sum variable.
}
printf("Decimal form =%ld",sum); // printing the sum to get
the decimal form
getch();
}
// Hope it solves your problem, ANy more assistance
honey.gupta13@yahoo.com

Is This Answer Correct ?    15 Yes 9 No

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

Answer / naveen bhatt

#include<stdio.h>
#include<conio.h>
void main()
{
int i,r,d,num;
for(i=1;i<=num;i++)
r=num%2;
num=d*num/2;
printf("\n the valueis=%d",r);
getch();
}

Is This Answer Correct ?    4 Yes 9 No

Post New Answer

More C Interview Questions

what are the advantages & disadvantages of unions?

2 Answers  


an algorithem for the implementation of circular doubly linked list

1 Answers  


Is c high or low level?

0 Answers  


What is unary operator?

0 Answers  


Is null always defined as 0(zero)?

0 Answers  






void main() { int i=5; printf("%d",i++ + ++i); }

21 Answers   ME,


which do you prefer C or Pascal?

1 Answers  


WHAT IS FLOAT?

3 Answers  


Write a C++ program to give the number of days in each month according to what the user entered. example: the user enters June the program must count number of days from January up to June

0 Answers  


what are brk, sbrk?

1 Answers   Oracle,


write a program in c language that uses function to locate and return the smallest and largest integers in an array,number and their position in the array. it should also find and return the range of the numbers , that is , the difference between the largest number and the smallest.

1 Answers  


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

0 Answers  


Categories