Class BinaryHelper
Contains various helpermethods to make bitfiddling easier.
Inheritance
Inherited Members
Namespace: Cosmos.Common
Assembly: Cosmos.Common.dll
Syntax
public class BinaryHelper
Methods
| Improve this Doc View SourceCheckBit(Byte, Byte)
Declaration
public static bool CheckBit(byte data, byte bit)
Parameters
Type | Name | Description |
---|---|---|
System.Byte | data | |
System.Byte | bit |
Returns
Type | Description |
---|---|
System.Boolean |
CheckBit(UInt16, UInt16)
Bitwise checks if the given bit is set in the data.
Declaration
public static bool CheckBit(ushort data, ushort bit)
Parameters
Type | Name | Description |
---|---|---|
System.UInt16 | data | A 16-bit unsigned int data |
System.UInt16 | bit | The zero-based position of a bit. I.e. bit 1 is the second bit. |
Returns
Type | Description |
---|---|
System.Boolean | Returns TRUE if bit is set. |
CheckBit(UInt32, UInt16)
Bitwise checks if the given bit is set in the data.
Declaration
public static bool CheckBit(uint data, ushort bit)
Parameters
Type | Name | Description |
---|---|---|
System.UInt32 | data | A 32-bit unsigned int data. |
System.UInt16 | bit | The zero-based position of a bit. I.e. bit 1 is the second bit. |
Returns
Type | Description |
---|---|
System.Boolean | Returns TRUE if bit is set. |
FlipBit(Byte, UInt16)
Flips the bit value at the given position in the data, from low to high, or from high to low.
Declaration
public static byte FlipBit(byte data, ushort bitposition)
Parameters
Type | Name | Description |
---|---|---|
System.Byte | data | A byte of data. |
System.UInt16 | bitposition | A bit position to change. |
Returns
Type | Description |
---|---|
System.Byte | The same data, but with one bit changed. |
FlipBit(UInt32, UInt16)
Flips the bit value at the given position in the data, from low to high, or from high to low.
Declaration
public static uint FlipBit(uint data, ushort bitposition)
Parameters
Type | Name | Description |
---|---|---|
System.UInt32 | data | A 32-bit unsigned int of data. |
System.UInt16 | bitposition | A bit position to change. |
Returns
Type | Description |
---|---|
System.UInt32 | The same data, but with one bit changed. |
GetByteFrom32bit(UInt32, Byte)
Get 32-bit unsigned int from 32-bit unsigned int, starting from a given offset.
Declaration
public static byte GetByteFrom32bit(uint data, byte offset)
Parameters
Type | Name | Description |
---|---|---|
System.UInt32 | data | A 32-bit unsigned int data. |
System.Byte | offset | The offset (in bytes) from the start of the data. |
Returns
Type | Description |
---|---|
System.Byte | Extracted 8-bit unsigned int (byte). |
Exceptions
Type | Condition |
---|---|
System.ArgumentException | Thrown when offset is greater then 24. |