如何打印一位?

如何打印一位?

问题描述:

请告诉我如何打印一些内容,例如printf("%d",bit);.

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

如果bit只是一个包含最低有效位中所需值的整数,则:

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.