can someone gimme hint for making program that converts binary number to decimal number?
I think if i can find number of digits in input, then i can do something.. but how can I find number of digits in input?
can someone gimme hint for making program that converts binary number to decimal number?
I think if i can find number of digits in input, then i can do something.. but how can I find number of digits in input?
>>can someone gimme hint for making program that converts binary number to decimal number?
I'm sure a board search will help. This does seem to be the topic of the week
>>but how can I find number of digits in input?
How do you obtain the input? From the user? Did you get it as a string with fgets()? If so, how about using strlen()?
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
Converting binary to decimal is easy if the binary number is a string. Just do something like this.
Code:#include <stdio.h> #include <string.h> void revstr( char *str ) { char *str_start = str; char *str_end = &str[strlen( str ) - 1]; char chr_hold; while( str_start < str_end ) { chr_hold = *str_start; *str_start++ = *str_end; *str_end-- = chr_hold; } } long bincon( char *bin ) { long dec = 0, base = 1; revstr( bin ); while( *bin != '\0' ) { if( *bin++ == '1' ) dec += base; base <<= 1; } return dec; } int main() { char bin[] = "1011010" /* Put a binary string here (ex. "1011010") */; printf( "The decimal value is %ld\n", bincon( bin ) ); return 0; }
Processing error: Stupidity detected.
------------------------------
Dr. Bebop
Windows XP Professional Ed.
Microsoft Visual Studio 6
Post us your code and we help you with it.
Mr. C.