Hello! I am trying to convert a String to an array of HEX. For example I have a String s = "Hello World", I want a function where I can pass the string and returns an array of HEX equivalent as such, array = {0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x57, 0x6F, 0x72, 0x6C, 0x64}.
I tried using this code but it doesn't convert with the "0x" at the begining, plus the array is inverted.
Umm, do you mean reversed? That's obvious in the code, so you can fix that pretty easy, no?
Not sure what you mean here.
All in all, your not describing your problem, you're picking nits with someone else's code. Try telling us again what it is you want - I think it's "an array containing the hexadecimal equivalent of the characters in a string", but that's so simple it can't be, can it?
C
Trick is, your "characters" are "hexadecimal numbers". So what "conversion" needs doing? Or are you asking to transfer each character in the string into a value in the array?
Exactly! For example "Hello world" will be passed to the function and the function returns an array as such array = {0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x57, 0x6F, 0x72, 0x6C, 0x64} where 0x48 is the "H", 0x65 is the "e" and so on...
That is a little bit tricky in C. You have to return a pointer to the array, and the array has to be in some persistently allocated memory, because memory allocated by a function is released when it returns.
What do you need this for? There is probably an easier way to do the unspecified task that the code that you have requested, does.
it seems you do not understand something... Aes algorithm does not require "array of HEX"
in C++ "array of HEX" or "array of chars" or "array of decimals" not more than different representations of the same data and not need any transformation at all
Let's get down to the nitty gritty. What data type does the AES software expect as input? Can we please see some detail about that? Are you calling a function in some AES support module? Details...