2013-11-28 48 views
0

所以我有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 

回答

4

需要0x前缀,然后资本X来获得资本C和08说的前缀用0补足8个字符

fprintf(outputFile, "0x%08X", 12); 
4

%08x

会给你合适的位数。只需将0x作为装饰摆放在前面。

%08X将打印字母作为上限。

1

试试这个

#include<stdio.h> 
void main() 
{ 
int x; 
x=12; 

printf("%#010x\n",x); 
} 
0
fprintf(outputFile, "%#.8x", 12); 

#标志指定替代形式,其格式为0x,格式为x.8指定的精度为8,这是为x格式显示的最小位数。