Hey all. I want to use print to print hex numbers in the form 0x###, but if the number is 0, I want to omit the 0x part. How can I do this?
Thanks!
Hey all. I want to use print to print hex numbers in the form 0x###, but if the number is 0, I want to omit the 0x part. How can I do this?
Thanks!
Why make it hard?
if number = 0 printf without formatting else printf with formatting
printf("%#x", number);
Note that this does exactly what you want. If the value of number is 0, it prints 0, otherwise it prints in hex. Example:
int x = 0;
int y = 548548;
printf("%#x %#x\n", x, y);
Results in:
0 0x85ec4