I woud like to ask, what bin-'0'
means in this piece of code which convert binary number to decimal. Thanks.
#include <stdio.h>
#include <stdlib.h>
int main(){
char bin;
int dec = 0;
printf("Binary: \n");
bin = getchar();
while((bin != '\n')){
if((bin != '0') && (bin != '1')){
printf("Wrong!\n");
return 0;
}
printf("%c",bin-'0'); // ?
dec = dec*2+(bin-'0'); // ?
bin = getchar();
}
printf("Decimal: %d\n", dec);
return 0;
}