Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When working with a wireless driver module, noise in the wireless medium is reported to the module as a s32 data type, which is defined in linux/types.h.

I would like to use printk() to print out this value to the syslog, however when I do I get unintelligible results. Current attempts have been:

printk("%d", val);  
printk("%d", (int) val);  
printk("%3i", (int)val);  
printk("%3i", val);  
printk("%lx", val);  
printk("%lx", long val);  

I don't understand is how to format this for printing. I have also not been able to find any information thus far on how to do so.

Since it deals with kernel data types, I thought it might be appropriate to post in askubuntu.

share|improve this question
My talk of sign of extenion was misleading and have removed it, the s32 type is an explicitly sized data type, used in the case where certain hardware registers require 32 bits. – Radagasp Jan 25 '13 at 21:20
You can always edit your question to improve/correct it :-) – guntbert Jan 25 '13 at 21:21
Btw can you add name of function returning that __s32? – przemo_li Jan 25 '13 at 21:49

Because you know it is a 32-bit int, try casting it before passing it to printk:

printk("%d", (int32_t) val);
share|improve this answer
typedef         __s32           int32_t;

So you should treat it like simple integer value.

share|improve this answer
It seems the OP tried that in line 1 of the original code examples; something is missing – Travis G. Jan 25 '13 at 21:31
up vote 0 down vote accepted

It turns out that the sign extension was important:

sign_extend32(AR5K_REG_MS(value, AR5K_PHY_NF_MINCCA_PWR), 8)


AR5K_PHY_NF_MINCCA_PWR 0x0ff80000 /* Minimum measured noise level, read from hardware in 1 dBm units */

The AR5K_REG_MS functions masks and shifts that value read from the hardware register with respect to the minimum measured noise level .

sign_extend32 /* sign extend a 32-bit value using specified bit as sign-bit */

After these are completed, the number can be written to syslog using '%d' for formatting.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.