所以我有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
格式顯示的最小位數。