This function convert binary to decimal , Please can you code this function diff
ID: 3637771 • Letter: T
Question
This function convert binary to decimal , Please can you code this function differently
comp_bin is 1'scomplement function
---------------------------------
int binaire_dec(char bin[])
{
int i;
int valeur = 0;
int inverse;
char tab[NB_BITS];
strncpy(tab,bin,NB_BITS);
inverse = 0;
if(bin[NB_BITS-1] == '1')
{
comp_bin(tab);
inverse = 1;
}
for(i=0;i<NB_BITS;i++)
{
if(tab[i] == '1')
{
valeur+= (int)pow(2.0,i);
}
}
if(inverse)
{
valeur++;
valeur*=-1;
}
return valeur;
}