这种c#位移位方法做什么?

这种c#位移位方法做什么?,c#,byte,bitwise-operators,C#,Byte,Bitwise Operators,这个方法基本上是从java程序复制而来的,但我担心它在c语言中无法正常工作# 如果ID是一个字节,它做什么 public int getBit(int position) { return (ID >> (position - 1)) & 1; } 从ID中提取传递位置的位。 位置应为1-8 返回位值(0-1) 例如: ID = 128; // 10000000 getBit(8); // returns 1 ID = 127; //

这个方法基本上是从java程序复制而来的,但我担心它在c语言中无法正常工作# 如果ID是一个字节,它做什么

public int getBit(int position)
    {
        return (ID >> (position - 1)) & 1;
    }

从ID中提取传递位置的位。
位置应为1-8
返回位值(0-1)

例如:

ID = 128;  // 10000000
getBit(8); // returns 1

ID = 127;  // 01111111
getBit(8); // returns 0

如果(位置-1)处的位为1,则返回非零,否则返回0

在C#和Java中的行为相同