decimal to hex conversion in C
I need to conver decimal numbers to 4 digit lower-case hex numbers prefixed by 0x.
"%X" is good enough, but this is not exactly what I want.printf("hex num is: %X\n", num);
开发者_如何学Python
I guess you need either 0x%04x
or %#06x
.
%x
means lower-case hex.0
means padding with zeros if shorter than the specified number of digits.4
or6
specifies the desired width.#
means0x
prefix.
Is printf("hex num is : 0x%.4x\n", num);
what you want?
Use printf("hex num is : 0x%x\n", num);
.
精彩评论