How do I print one bit?

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

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

6条回答
  •  心在旅途
    2021-01-18 05:04

    If bit is just an int that contains the value you want in the least significant bit, then:

    printf("%d", bit & 0x1);
    

    should do it. The & is doing a binary-AND with a number with only the first significant bit set, so you're removing all the rest of the bits in the integer.

提交回复
热议问题