c - 如何将 unsigned int 格式化为 8 位十六进制数?

我想将一个无符号整数格式化为一个带有前导零的 8 位长字符串。

这是我目前所拥有的:

  unsigned int number = 260291273;
  char output[9];
  sprintf(output, "%x", number);
  printf("%s\n", output); // or write it into a file with fputs

打印“f83bac9”,但我想要“0f83bac9”。如何实现格式化?

最佳答案

使用“%08x”作为格式字符串。

https://stackoverflow.com/questions/3531970/

相关文章:

python - 格式化数字,使它们在小数点上对齐

php - mysql时间戳转换/格式化通知: A non well formed numeric

iphone - 在Objective-C中将小数转换为分数?

java - RSS 2.0 提要中的 RFC-822 日期时间格式 : CET not accep

java - 无法解析自定义日期格式。 ( java )

xml - 在 Scala 中生成格式化的 XML

git - Git 提交消息的推荐格式

python - 带有负索引的 str.format(list) 在 Python 中不起作用

git - 如何为 git diff 中使用的寻呼机设置标签大小?

formatting - 如何打印具有所有可用精度的 Rust float ?