Implementation of Double-Dabble Method in C
C code to convert a binary string into decimal:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
char bin[65];
scanf("%s",bin);
int len=strlen(bin);
long long dec=bin[0]-'0';
for(int i=1;i<len;i++)
{
dec=dec*2+(bin[i]-'0');
}
printf("%lld\n",dec);
return 0;
}
No comments