Write a program in C Language to convert binary number into decimal.

//Binary To Decimal Conversation
#include<stdio.h>
#include<string.h>
#include<math.h>
int main(){
char getbtd[]="110011.0101";
int length,dc=0,i=0,p1=0,p2=-1;
float sum=0;
length = strlen(getbtd);
while(1)
{
if(getbtd[i] == '.')
break;
else
dc++;
i++;
}
for(i=dc-1; i>=0; i--)
{
sum = sum + ((int)(getbtd[i]-'0')*pow(2,p1));
p1++;
}
for(i = dc + 1 ; i < length ; i++)
{
sum = sum + ((int)(getbtd[i]-'0')*pow(2,p2));
p2--;
}
printf("Decimal No is: %f",sum);
}
//Output
// Decimal No is: 51.312500

All Questions :- (Click here to View)

2) Write a program in C Language to convert decimal numbers into binary. Ans:-  (Click here to View)

No comments:

Get new posts by email:


APY Logo