Skip to main content

Class BitHelpers

A static class with methods to help with bit operations

Assembly: Meadow.Contracts.dll
View Source
public static class BitHelpers

Methods

SetBit(byte, byte, byte)

Returns a new byte mask based on the input mask, with a single bit set. To the passed in value.

View Source
public static byte SetBit(byte mask, byte bitIndex, byte value)
Returns

System.Byte

Parameters
TypeNameDescription
System.BytemaskThe original byte mask value.
System.BytebitIndexThe index of the bit to set.
System.BytevalueThe value to set the bit. Should be 0 or 1.

SetBit(byte, byte, bool)

Returns a new byte mask based on the input mask, with a single bit set. To the passed in value.

View Source
public static byte SetBit(byte mask, byte bitIndex, bool value)
Returns

System.Byte

Parameters
TypeNameDescription
System.BytemaskThe original byte mask value.
System.BytebitIndexThe index of the bit to set.
System.BooleanvalueThe value to set the bit. true for 1, false for 0.

SetBit(short, byte, bool)

Returns a new 16-bit short with the single bit set or cleared

View Source
public static short SetBit(short mask, byte bitIndex, bool value)
Returns

System.Int16

Parameters
TypeNameDescription
System.Int16maskThe original value
System.BytebitIndexThe index of the bit to affect
System.BooleanvalueTrue to set, False to clear

GetBitValue(byte, byte)

Returns the value of the mask at the given ordinal.

View Source
public static bool GetBitValue(byte mask, byte bitIndex)
Returns

System.Boolean

Parameters
TypeName
System.Bytemask
System.BytebitIndex

GetBitValue(short, byte)

Determines if a specified bit in a 16-bit short is set

View Source
public static bool GetBitValue(short mask, byte bitIndex)
Returns

System.Boolean

Parameters
TypeNameDescription
System.Int16maskThe value to check
System.BytebitIndexThe index of the bit to check

ToInt16(byte[])

Converts the first 2 bytes of an array to a little-endian 16-bit short

View Source
public static short ToInt16(byte[] data)
Returns

System.Int16

Parameters
TypeName
System.Byte[]data