Question

I am doing calculator application.

For the Decimal, Binary, Octal and Hexadecimal numbers. For that I need to convert numbers from one to another number system. So can any one tell me about any built in functions for conversions, eg. Dec to Binary, in c++.

If there is no built in functions, can anyone suggest me a standard code to convert between Dec to Binary, Dec to Octal ,Dec to Hex and Vice a versa.

Thanks in advance.

No correct solution

OTHER TIPS

wsprintf can do some limited numeric conversions, but I'd generally advise against using it.

Although they're in the standard library instead of the Win32 API per se, I'd use std::to_string if your compiler/library are new enough to include it, and strtol otherwise.

For converting a number to a string, you can use a stringstream for hex, octal or decimal. For binary, you generally want to create a std::bitset from the number first, then write that to the stream.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top