Automata Questions – 9
Q9. Convert Binary to Decimal by using the existing function.
void binarytodecimal(number)
{
// Type your code here
}
void main()
{
int num;
scanf(“%d”, &num);
printf(“%d”, binarytodecimal(num);
}
Answer:
void binarytodecimal(number)
{
int dval=0, base=1, rem;
while(number > 0)
{
rem = number % 10;
dval = dval + rem * base;
num = number / 10;
base = base * 2;
}
return dval;
}
Login/Signup to comment