How do I print one bit?

后端 未结 6 472
野性不改
野性不改 2021-01-18 04:30

Please tell me how do I print a bit, like printf(\"%d\",bit);.

6条回答
  •  半阙折子戏
    2021-01-18 05:10

    To print the m-th bit (m from 1..16 or 32) of n:

    void print_bit(n, m)
    {
        printf("%d", n & (1 << (m - 1)));
    }
    

    Remove the - 1 bit if your bit counter starts at 0.

提交回复
热议问题