I am trying to convert a decimal integer into hexadecimal. I’ve done a lot of searching online, and have found many ways to do this. However, every way I found converts to a string; for example, I can convert 100 into “64”. That isn’t what I need to do. I want to be able to convert 100 into ‘0x64’, which is an entirely different matter. For some reason, I suspect the answer to be extremely simple, but I can’t seem to find/remember it. I’m writing in the C Programming Language, just to clarify. Any assistance or ideas would be much appreciated.
Thanks,
Hassan
You can’t “convert” a number from decimal to hexadecimal because it’s … a number (usually stored in memory as two’s complement). All representations of the same number in all possible positional systems live at exactly the same point on the number line. You can though print it in different bases: