Answers for "Binary number to Decimal number"

0

Binary number to Decimal number

#include <stdio.h>
int main()
{
      int  num, binary_val, decimal_val = 0, base = 1, rem;
      printf("Insert a binary num (1s and 0s) \n");
      scanf("%d", &num); 
      binary_val = num;
      while (num > 0)
      {
          rem = num % 10;
          decimal_val = decimal_val + rem * base;
          num = num / 10 ;  //these are the correct lines
          base = base * 2;  //these are the correct lines
      }
      printf("%d \n", binary_val);
      printf("%d \n", decimal_val);
   return 0;
}
Posted by: Guest on April-28-2022

Code answers related to "Binary number to Decimal number"

Browse Popular Code Answers by Language