Hi,
Can anyone advise on how I can convert a string to a hex string? (And subsequently perform an AND operation on two hex strings.) I have a string value passed in (e.g., 1006), and I want to turn that into hex (0x1006).
I have tried the following:
[B]// Assume [I]inputData[/I] and [I]mask[/I] to be strings (e.g., "1006", "FF")[/B]
unsigned char *hexResult;
char *hex1[20];
char *hex2[20];
*hex1 = "0x";
*hex2 = "0x";
strcat(*hex1, inputData);
strcat(*hex2, mask);
hexResult = (unsigned char *)((int)hex1 & (int)hex2);
At the first strcat operation, an access violation is occurring.
I have also tried another way:
[B]// Assume [I]inputData[/I] and [I]mask[/I] to be strings (e.g., "1006", "FF")[/B]
unsigned char *hexResult;
char hex1[3] = "0x";
char hex2[3] = "0x";
strcat(hex1, inputData);
strcat(hex2, mask);
hexResult = (unsigned char *)((int)hex1 & (int)hex2);
But during debugging, when the second strcat operation is performed, the value in hex1 appears to be getting lost, and is set to "". Any ideas why this happens? Or suggestions as to how I can resolve?