Is there any built in functions in c++ win 32 for number system conversions?

StackOverflow https://stackoverflow.com/questions/22140158

  •  19-10-2022
  •  | 
  •  

Вопрос

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.

Нет правильного решения

Другие советы

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top