Anyone know any good online converters?
One that actually converts a binary decimal to base 10 decimal?
Like 10101.001 -> Base 10 decimal.
All converters I have found online round up the numbers.
Anyone know any good online converters?
One that actually converts a binary decimal to base 10 decimal?
Like 10101.001 -> Base 10 decimal.
All converters I have found online round up the numbers.
How about listing what you've already looked at so people wont suggest them again?
What about the calculator program that comes with your OS?
My homepage
Advice: Take only as directed - If symptoms persist, please see your debugger
Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"
It doesn't take in binary decimals like 10101.001
No decimal places taken.
Are you talking about fixed point representation?
Floating point is a lot more common.
Last edited by mike_g; 11-20-2007 at 01:14 AM.
It wouldn't be that hard to write your own code to do it.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
I would easily write my code, if I could find out the method for doing it properly, then checking it. Otherwise I would get wrong answers if my method was wrong
The method is that you start with the same algorithm as for binary string to ascii [you could in fact do it with strtol() for this part] up to the decimal dot. After the dot, each digit is half of the previous, with the first one after the dot being "worth" 0.5.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Well the main reason I was asking was because I have an exam tomorrow. And while I know how to do it, I was practicing some problems, but there were no answers, so I wanted to check my answers with some online converter.
Writing a program would take a while :P
How about that one - didn't take too long, did it?Code:#include <stdio.h> #include <string.h> #include <stdlib.h> int main() { for(;;) { char input[100]; char *p; double d = 0.0; double m = 0.5; int len; printf("Enter binary 'float' number (or 9 to exit):"); if (fgets(input, sizeof(input), stdin) == NULL) break; len = strlen(input); if (input[len-1] == '\n') { input[len-1] = 0; } else { int ch; printf("Error: input too long - ignored\n"); while((ch = getchar()) != '\n' && ch != EOF) ; goto err; } p = input; if (*p == '9') { break; } while(*p && *p != '.') { if (*p < '0' || *p > '1') { printf("Invalid input\n"); goto err; } d *= 2.0; d += *p - '0'; p++; } if (*p) { if (*p != '.') { printf("Expected a '.'\n"); goto err; } p++; while(*p) { if (*p < '0' || *p > '1') { printf("Invalid input\n"); goto err; } d += (*p - '0') * m; m *= 0.5; p++; } } printf("Decimal: %f\n", d); err: continue; } return 0; }
Edit: Appologies for short variable names and use of goto. If anyone would like to take the code and modify it to use longer names and no goto's, feel free.
--
Mats
Last edited by matsp; 11-20-2007 at 05:45 AM.
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Pretty cool mats, I guess I'll use it =) but I won't modify it because it will take me a while to understand it lol.
Thanks, did you actually type all that out?
To do that, it would take me several hours lol.
Sorry for bringing up a somewhat "old" topic, but you could also have done this, ie:
Tadam, by using only XP calculator (in scientific mode).Code:10101.001 = 10101001 * 2^-3 = <convert to decimal, let's say with XP calculator> 169 * 2^-3 = 169 / 2^3 = 169 / 8 = 21.125
Sure, that'll work.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.