I'm trying to convert a hex number to a character in C++. I looked it up but I can't find an answer that works for me.
Here is my code:
char mod_tostring(int state, int index, int size) {
int stringAddress = lua_tolstring(state, index, 0);
const char* const Base = (const char* const)stringAddress;
return Base[0];
};
Base[0] would return a hex number like: 0000005B
If you go here http://string-functions.com/hex-string.aspx and put 0000005B as the input it outputs the character "[". How would I also output [?
To print a number as a character, you can either assign it to a
char
variable or cast it to achar
type:You could also use
snprintf
:Example program:
Output:
Try this:
Output should be: 0x5B assuming Base[0] is 0000005B.