//C语言:将一个由字符0和1组成的表示二进制数的字符串,转换成相应的十进制数返回。

 //函数fun:将一个由字符0和1组成的表示二进制数的字符串,转换成相应的十进制数返回。

 1 #include   <stdio.h>
 2 #pragma warning (disable:4996)
 3 #define    N   16
 4 /**********************found***********************/
 5 int  fun( char  s[])  //形参不要使用定值
 6 {  int  i,  n = 0;
 7 /**********************found***********************/
 8    for (i=0; i<strlen(s) ; ++i)
 9 /**********************found***********************/
10         n = n*2 + (s[i] -'0') ; //字符串0的ASCII码为48
11    return  n;
12 }
13 main( )
14 {  char  num[] = "10011";    int  n;
15    n = fun(num);
16    printf( "%s-->%d
", num, n );
17 }
原文地址:https://www.cnblogs.com/ming-4/p/10506080.html