All pastes #194274 Raw Edit

Unnamed

public text v1 · immutable
·published 2006-10-07 19:15 UTC
rendered paste body
        // Get Bit from a byte specified. 
        // Pass 0-7 for the bitNum param, where 0 is the least significant bit.
        public static byte GetBit(byte uByte, int bitNum)
        {

            // ^ is not to the power in C#! It's XOR. Use System.Math.Pow()

            // Return desired bit. -- 
            if ((uByte & (byte)Math.Pow(2,  bitNum)) > 0)
            {
                return 1;
            } else {
                return 0;
            }

        }