I have the following: int num=500; char text[8];
how do I make it so that text ends up being the hex 0x500, or 1280?
edit: i see that its pretty simple to make it text, like in some of the answers. But I need this text to be interpreted as a hex by C. So in reality it should be an unsigned hex int.
This should do it.
This is assuming you on purposely didn't convert
num
to hexadecimal, if this wasn't on purpose this createstext
with the integer converted to hexadecimal:There is an exercise in K&R, second chapter if I'm not mistaken, that asks to do this very thing. If you are having difficulties I suggest you look up hexadecimal aritmetic on Wikipedia.