2013-11-28 87 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格式顯示的最小位數。