sprintf(lstrBuf, "%02X", lstrSignature[lnIndex - 1]) ????

  • Thread starter Thread starter Marja Ribbers-de Vroed
  • Start date Start date
M

Marja Ribbers-de Vroed

I'm trying to understand a C++ function that has been given to me. Among other things it has the following code fragment in it:

lstrResultStr = "";
for (lnIndex = lnSignature; lnIndex > 0; lnIndex--)
{
sprintf(lstrBuf, "%02X", lstrSignature[lnIndex - 1]);
lstrResultStr += lstrBuf;
}

I think this means that lstrResultStr becomes the reverse of lstrSignature, but I don't understand what's happening on the line with:
sprintf(lstrBuf, "%02X", lstrSignature[lnIndex - 1]);

Can someone please explain what this means?
Thanks in advance.

Regards, Marja
 
Marja said:
I'm trying to understand a C++ function that has been given to me.
Among other things it has the following code fragment in it:

lstrResultStr = "";
for (lnIndex = lnSignature; lnIndex > 0; lnIndex--)
{
sprintf(lstrBuf, "%02X", lstrSignature[lnIndex - 1]);
lstrResultStr += lstrBuf;
}

I think this means that lstrResultStr becomes the reverse of
lstrSignature, but I don't understand what's happening on the line
with:
sprintf(lstrBuf, "%02X", lstrSignature[lnIndex - 1]);

%02X converts an integer type (in this case, a char) to a two digits
hexadecimal string. So, lstrResultStr becomes the concatenation of the hex
representations of the characters in lstrSignature, in reverse order,
assuming that lstrResultStr is a string type that supports the obvious
interpretation of +=.

"ABC" in lstrSignature results in "424341" in lstrResultStr.

-cd
 
%02X converts an integer type (in this case, a char) to a two digits
hexadecimal string. So, lstrResultStr becomes the concatenation of the hex
representations of the characters in lstrSignature, in reverse order,
assuming that lstrResultStr is a string type that supports the obvious
interpretation of +=.

"ABC" in lstrSignature results in "424341" in lstrResultStr.

Thanks Carl.

Regards, Marja
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top