sprintf not printing 32 bit variables correctly

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

sprintf not printing 32 bit variables correctly

Jump to solution
2,293 Views
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
Labels (1)
Tags (1)
0 Kudos
1 Solution
773 Views
stanish
NXP Employee
NXP Employee
Hi daneb,

I'd suggest you to try:

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


this might help...

stanish

View solution in original post

0 Kudos
2 Replies
773 Views
Lundin
Senior Contributor IV
The %X specifier takes an int as argument, so the compiler behaves as expected.
774 Views
stanish
NXP Employee
NXP Employee
Hi daneb,

I'd suggest you to try:

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


this might help...

stanish
0 Kudos