How do I convert a string of decimal numbers into ASCII? [closed]

Solution 1:

Looks like your input is a series of 2-byte decimal numbers. Each pair represents an ascii char. That's an unusual way to encode data. If the input stream had any ascii char with an ordinal value over 99, it couldn't be encoded.

A quick decode loop could look like the following. Making use of strtol to convert each pair of numbers back to an integer.

std::string s = "54565550445154544949445056555748445254555650445350485354445350535053445349565453445053564955445453535153445552494844524650504450485049474949475148445048585558501310";
std::string result;

size_t pairs = s.length() / 2;

for (size_t i = 0; i < pairs; i++)
{
    char tmp[3] = { s[i*2], s[i*2 + 1], '\0' };

    char c = (unsigned char)(strtoul(tmp, nullptr, 10));

    result += c;
}
std::cout << result << "\n";

Prints out the following:

6872,36611,28790,46782,52056,52525,51865,25817,65535,7410,4.22,2021/11/30,20:7:2