Is there a printf converter to print in binary format?

前端 未结 30 3277
盖世英雄少女心
盖世英雄少女心 2020-11-21 06:20

I can print with printf as a hex or octal number. Is there a format tag to print as binary, or arbitrary base?

I am running gcc.

printf(\"%d %x %o         


        
30条回答
  •  被撕碎了的回忆
    2020-11-21 06:50

    No standard and portable way.

    Some implementations provide itoa(), but it's not going to be in most, and it has a somewhat crummy interface. But the code is behind the link and should let you implement your own formatter pretty easily.

提交回复
热议问题