How to write an algorithm to do a binary to decimal conversion ?

/* part of work copied from http://www.sanfoundry.com/c-program-binary-number-into-decimal/ */ #include <stdio.h> btd() { int num, binary_val, decimal_val = 0, base = 1, rem; printf(“Enter a binary number : “); scanf(“%d”,&num); binary_val = num; while ( num > 0 ) { rem = num % 10; decimal_val = decimal_val + rem * base; num = num / …