Visual Studio C++ Strings in Hexa

Asked

Viewed 38 times

-1

I am creating a program in Visual Studio C++ with UI to do RS-232 communication with some weather cameras, for that I have to send a String in Hexa. String is sent in this format:

    String^ a1 = "\x01";
    String^ a2 = "\x00";
    String^ a3 = "\x00";
    String^ a4 = "\x01";
    String^ a5 = "\x0D";
    String^ a6 = "\x0A";

    String^ final = a1 + a2 + a3 + a4 + a5 + a6;

My problem is to be able to read the answer from the cameras, this answer comes in the same format as the final String, that is, how to separate the String and convert to a Decimal format?

I have tried equal to an int variable, but I had no results..

  • That’s not C++, that’s C#

1 answer

0

You can use the comma

std::string a1 = "\x0A";

int x;
std::stringstream ss;
ss << std::hex << a1;
ss >> x;

std::string final{std::to_string(x)};
std::cout << final << "\n";
  • Thanks for the answer but unfortunately it didn’t help. In the case of x0A is the ascii corresponding to a Line Feed. And doing this conversion what appears is "-858993460".

Browser other questions tagged

You are not signed in. Login or sign up in order to post.