sprintf not printing 32 bit variables correctly

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

sprintf not printing 32 bit variables correctly

跳至解决方案
3,240 次查看
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,720 次查看
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,720 次查看
Lundin
Senior Contributor IV
The %X specifier takes an int as argument, so the compiler behaves as expected.
1,721 次查看
stanish
NXP Employee
NXP Employee
Hi daneb,

I'd suggest you to try:

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


this might help...

stanish
0 项奖励
回复