printf()的格式为十六进制 [英] printf() formatting for hex
问题描述
这是一个多重要的问题一个奇怪的查询,但为什么打印十六进制与前导零的8位数字时,这是否%#08X
不显示同样的结果为0x%08X
?
This is more of a curious query than an important question, but why when printing hex as an 8 digit number with leading zeros, does this %#08X
Not display the same result as 0x%08X
?
当我尝试使用前者, 08
格式化标志被删除,它不只是工作 8
。
When I try to use the former, the 08
formatting flag is removed, and it doesn't work with just 8
.
同样我只是好奇。
推荐答案
的#
部分给出了一个 0X
在输出字符串。在 0
和 X
计入中列出的8字 08
部分。你需要问的10个字符,如果你希望它是一样的。
The #
part gives you a 0x
in the output string. The 0
and the x
count against your "8" characters listed in the 08
part. You need to ask for 10 characters if you want it to be the same.
int i = 7;
printf("%#010x\n", i); // gives 0x00000007
printf("0x%08x\n", i); // gives 0x00000007
printf("%#08x\n", i); // gives 0x000007
也在不断变化 X
,影响输出字符的外壳。
Also changing the case of x
, affects the casing of the outputted characters.
printf("%04x", 4779); // gives 12ab
printf("%04X", 4779); // gives 12AB
这篇关于printf()的格式为十六进制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!