Source/BooleanByte.cs
/// <summary>
/// Sets the boolean value to the specified index
/// </summary>
/// <param name="index">The bit of the byte to set (0-7)</param>
/// <param name="value">The boolean value to set the bit as</param>
Sets the boolean value to the specified index
Sets the boolean value to the specified index
public void SetBit(int index, bool value)
        {
            if (index >= 8 && index < 0)
                throw new ArgumentOutOfRangeException("Index must refer to a bit, 0-7.");
            if (value)
            {
                data = (byte)(data | (1 << index));
            }
            else
            {
                data = (byte)(data & ~(1 << index));
            }
        }
public void SetBit ( int index , bool value ) { if ( index >= 8 && index < 0 ) throw new ArgumentOutOfRangeException ( " " ) ; if ( value ) { data = ( byte ) ( data | ( 1 << index ) ) ; } else { data = ( byte ) ( data & ~ ( 1 << index ) ) ; } }
Sets the boolean value to the specified index
Sets the boolean value to the specified index
//Validation //Left-shift 1, then bitwise OR //Left-shift 1, then take complement, then bitwise AND
index
int
The bit of the byte to set (0-7)
The bit of the byte to set ( 0 - 7 )
value
bool
The boolean value to set the bit as
The boolean value to set the bit as