sprintf not printing 32 bit variables correctly

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

sprintf not printing 32 bit variables correctly

ソリューションへジャンプ
3,247件の閲覧回数
deneb
Contributor II
Hello Experts
 
I am printing an unsigned 32-bit integer as following:
 
sprintf(str,"%8X", (unsigned long) sig_pow);
 
where sig_pow is defined as unigned long itself. But strangely it always prints the upper 2 bytes, i.e., most significant 4 hex characters. Anyone has some idea on what is going wrong?
 
Thanks
deneb
ラベル(1)
タグ(1)
0 件の賞賛
返信
1 解決策
1,727件の閲覧回数
stanish
NXP Employee
NXP Employee
Hi daneb,

I'd suggest you to try:

 sprintf(str,"%8LX",sig_pow);


this might help...

stanish

元の投稿で解決策を見る

0 件の賞賛
返信
2 返答(返信)
1,727件の閲覧回数
Lundin
Senior Contributor IV
The %X specifier takes an int as argument, so the compiler behaves as expected.
1,728件の閲覧回数
stanish
NXP Employee
NXP Employee
Hi daneb,

I'd suggest you to try:

 sprintf(str,"%8LX",sig_pow);


this might help...

stanish
0 件の賞賛
返信