Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I printk in binary?

I have a bitmap that I need to debug, and it would be much easier for me to printk the number in binary rather than decimal. Can I do this?

like image 265
alexgolec Avatar asked Dec 21 '22 20:12

alexgolec


2 Answers

Perhaps try hex or octal:

printk("%02X", mybyte);
printk("%03o", mybyte);
like image 183
Yann Ramin Avatar answered Jan 03 '23 04:01

Yann Ramin


There is a function to print a binary value in arch/parisc/kernel/traps.c, called printbinary(). You can copy it into your code (or just link it if you happen to be on parisc). Better still move it somewhere generic in the kernel tree, eg. lib, and send a patch to LKML.

like image 33
mpe Avatar answered Jan 03 '23 05:01

mpe