473,396 Members | 1,786 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

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
Dec 18 '05 #1
2 1406
Marja Ribbers-de Vroed wrote:
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
Dec 18 '05 #2
> %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
Dec 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.