C++ a binary string into integer solution

  • 2020-04-01 23:27:19
  • OfStack

The code is as follows:

<SPAN style="FONT-SIZE: 18px"> char* p = "1010110001100";
 int n = 0;
 for(int i=0;i<strlen(p); i++)
 {
  n = n * 2 + (p[i] - '0');
 }
 printf("%dn", n);</SPAN>

Related articles: