开发者

decimal to hex conversion in C

开发者 https://www.devze.com 2023-04-05 10:46 出处:网络
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.

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

精彩评论

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

关注公众号