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
  • 334,321
  • 69
  • 703
  • 674
Glen654
  • 1,102
  • 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
  • 213,761
  • 22
  • 232
  • 286
1

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

spender
  • 117,338
  • 33
  • 229
  • 351