开发者

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 or 6 specifies the desired width.
  • # means 0x prefix.


Is printf("hex num is : 0x%.4x\n", num); what you want?


Use printf("hex num is : 0x%x\n", num);.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜