0

This method is pretty much copied from a java program, but I have worries it doesn't work as intended in c# if ID is a byte, what does this do?

public int getBit(int position)
    {
        return (ID >> (position - 1)) & 1;
    }
Tomasz Nurkiewicz
  • 324,247
  • 67
  • 682
  • 662
Glen654
  • 1,082
  • 3
  • 14
  • 18
  • http://stackoverflow.com/questions/141525/absolute-beginners-guide-to-bit-shifting/141873#141873 – Prix May 26 '12 at 19:47

2 Answers2

1

Extract from the ID the bit at the position passed.
Position should be 1-8
Returns the bit value (0-1)

For example:

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

ID = 127;  // 01111111
getBit(8); // returns 0
Steve
  • 208,592
  • 21
  • 221
  • 278
1

Returns non-zero if the bit at (position-1) is 1, otherwise returns 0

spender
  • 112,247
  • 30
  • 221
  • 334