Is there a printf converter to print in binary format?

前端 未结 30 2753
盖世英雄少女心
盖世英雄少女心 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:51

    Maybe a bit OT, but if you need this only for debuging to understand or retrace some binary operations you are doing, you might take a look on wcalc (a simple console calculator). With the -b options you get binary output.

    e.g.

    $ wcalc -b "(256 | 3) & 0xff"
     = 0b11
    

提交回复
热议问题