I am trying to convert a string pointer(I believe String^ is string pointer??) into a 2-digit hexdump string.
I have the main part working by utilizing sprintf to print the hex value into a buffer and copy it into the hexdump char array secretHex.
However, I was not able to convert the char array into String, it only display 'True' when I try printf the converted string.
Can someone give me an idea of what is happening at the end?
I would like to be able to print out the result hex as the initial String^ secretKey.
Thanks!!
String^ secretKey = "1122334455667788";
printf("1. %s\n", secretKey);
int n = 0;
char buffer1[17], buffer2[3], secretHex[33];
sprintf_s(buffer1, "%s", secretKey);
while (n < sizeof(buffer1) - 1) {
char value = buffer1[n];
sprintf_s(buffer2, "%02x", value);
secretHex[2 * n] = buffer2[0];
secretHex[2 * n + 1] = buffer2[1];
n++;
}
secretHex[sizeof(secretHex)-1] = '\0';
printf("The secretHex key is %s\n", secretHex);
String^ hex = System::Convert::ToString(secretHex);
printf("2. %s\n", hex);
//OUTPUT
1. 1122334455667788
The secretHex key is 31313232333334343535363637373838
2. True