如何打印一位? [英] How do I print one bit?
本文介绍了如何打印一位?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请告诉我如何打印一些内容,例如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.
这篇关于如何打印一位?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文