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;
}
Explanation / Answer
Example 1 #include void binary(int); void main(void) { int number; cout > number; if (number < 0) cout digit = substring(number, i); > /* where, say, substring(11011, 2) returns 0 */ > /* but I'm not sure about this part */ > > if(digit == 1) > decimal += pow(2,i); > } > > return decimal; > }Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.