所以我有12号我怎么印出它在格式打印出来的数字为十六进制数字
0x0000000C // where there is always the 0x in the beginning and always 8 digits after to
// represent the number
fprintf(outputFile, "%x", 12);
是给我:
cc
但我想:
0x0000000C
所以我有12号我怎么印出它在格式打印出来的数字为十六进制数字
0x0000000C // where there is always the 0x in the beginning and always 8 digits after to
// represent the number
fprintf(outputFile, "%x", 12);
是给我:
cc
但我想:
0x0000000C
需要0x前缀,然后资本X来获得资本C和08说的前缀用0补足8个字符
fprintf(outputFile, "0x%08X", 12);
%08x
会给你合适的位数。只需将0x
作为装饰摆放在前面。
%08X
将打印字母作为上限。
试试这个
#include<stdio.h>
void main()
{
int x;
x=12;
printf("%#010x\n",x);
}
fprintf(outputFile, "%#.8x", 12);
的#
标志指定替代形式,其格式为0x
,格式为x
。 .8
指定的精度为8,这是为x
格式显示的最小位数。