鉴于此代码以整数形式打印所有位:
private string getBitLiteral(bool bitVal)
{
if (bitVal)
{
return ("1");
}
else
{
return ("0");
}
}
Int64 intThisHand = 127;
for (int i = 64; i > 0; i--)
{
HttpContext.Current.Response.Write(
getBitLiteral((intThisHand & (1 << i)) != 0)
);
}
为什么会打印出来:
1000000000000000000000000011111110000000000000000000000000111111
首先,我是否正确循环,因为我希望最后 7 位数字是 1
其次,为什么中间有一些1?我希望它们都为 0,除了后面的 7 个 1。