use*_*710 5 c# bit-manipulation shift
我有一个int号而且我必须将它向右移几次.
x = 27 = 11011
x>>1= 13 = 1101
x>>2= 6 = 110
x>>3= 3 = 11
Run Code Online (Sandbox Code Playgroud)
我想获取已被删除的值位值.我必须得到:1,1,0
如何获取删除的值
对于最不重要的位,您可以x & 1在每次换档之前使用.如果要在不更改值的情况下随时获取自定义位,可以使用以下方法.
private static int GetNthBit(int x, int n)
{
return (x >> n) & 1;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
952 次 |
| 最近记录: |