Hey guys
Am working on this program, a part of which requires the input fixed-point binary number to be converted to decimal for example;
11001.101 to its equivalent mixed decimal number...........any suggestions(a function would be excellent :) )?

Recommended Answers

All 7 Replies

Split the problem into parts. If it were me, Id first make a function to convert a binary string to an integer, and then a second function to turn the fixed-point binary string into a double type.

#include <iostream>

int bin_to_int(char *binary) {
  // ...
}

double bin_to_double(char *binary_fixed_point) {
  // ...
}

int main() {
  // ...
}

Hope this helps.

commented: Good advice +30
#include <iostream>

int bin_to_int(char *binary) {
  // ...
}

double bin_to_double(char *binary_fixed_point) {
  // ...
}

int main() {
  // ...
}

Hope this helps.

You forgot to put the using namespace std; instruction in your snippet :P

You forgot to put the using namespace std; instruction in your snippet :P

using namespace std; isn't required even if you're using things from the std namespace. It's only to make it less annoying so you don't have to type std::cout , std::cin , etcetera.

using namespace std; isn't required even if you're using things from the std namespace. It's only to make it less annoying so you don't have to type std::cout , std::cin , etcetera.

That's true, I forgot about that (I only wouldn't say 'less annoying' as it can cause conflicts), but as he isn't doing any input/output #include <iostream> isn't even needed or am I wrong?

That's true, I forgot about that (I only wouldn't say 'less annoying' as it can cause conflicts), but as he isn't doing any input/output #include <iostream> isn't even needed or am I wrong?

Right, iostream is only needed if you're using cout, cin and their ilk.

but he said he needs to convert the inputed number so wouldnt that imply that he needs to use cout to ask for the number and cin to get it?

but he said he needs to convert the inputed number so wouldnt that imply that he needs to use cout to ask for the number and cin to get it?

Yes, but remember: we aren't writing the code for him, by the way: we already assumed that he knows how to do input/output, otherwise his question was something else (I mean, if he's asking about how to do conversion between a Fixed-Point Binary and a Decimal number, can't you assume then that he already knows at least the basics of C++ (including I/O)? YES) :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.