Initializing base value to 1 i . e 2 ^ 0
int base_t = 1 ; int len = num . Length ; for ( int i = len - 1 ; i >= 0 ; i -- ) { if ( num [ i ] == '1' ) dec_value = dec_value + base_t ; base_t = base_t * 2 ; } return dec_value ; }