近日开始学习C#,以便进行wp开发,发现一个很好用的代码示例:使用按位与运算来以二进制显示值
class ShowBits {
static void Main() {
int t;
byte val;
val = 123;
for(t=128; t > 0; t = t/2) {
if((val & t) != 0) Console.Write("1 ");
if((val & t) == 0)Console.Write("0 ");
}
}
}
输出结果:
0 1 1 1 1 0 1 1