Class ShortExtensions
- Namespace
- Ubiety.Dns.Core.Common.Extensions
- Assembly
- Ubiety.Dns.Core.dll
Provides extension methods for working with ushort values, such as retrieving bytes, setting flag values, and extracting flag information.
public static class ShortExtensions
- Inheritance
-
ShortExtensions
- Inherited Members
Methods
GetBytes(ushort)
Retrieves the byte representation of a ushort value.
public static IEnumerable<byte> GetBytes(this ushort value)
Parameters
Returns
- IEnumerable<byte>
IEnumerable<T> where T is byte, representing the bytes of the given value.
GetFlag(ushort, int)
Retrieves the value of a flag at the specified position within a ushort.
public static bool GetFlag(this ushort value, int position)
Parameters
valueushortushort from which to extract the flag.
positionintThe bit position of the flag to retrieve.
Returns
GetFlag(ushort, int, int)
Retrieves the value of a specified flag from a ushort.
public static ushort GetFlag(this ushort value, int position, int length)
Parameters
valueushortushort from which the flag's value will be retrieved.
positionintBit position within the ushort where the flag resides.
lengthintThe number of bits representing the flag value.
Returns
SetFlag(ushort, int, bool)
Sets a flag value at the specified position within a ushort value.
public static ushort SetFlag(this ushort value, int position, bool flagValue)
Parameters
valueushortushort to set the flag value on.
positionintThe position of the flag to set.
flagValueboolThe value of the flag, where true represents 1 and false represents 0.
Returns
SetFlag(ushort, int, int, ushort)
Sets a specific flag or flags within a ushort value by updating the bit(s) at a designated position.
public static ushort SetFlag(this ushort value, int position, int length, ushort flagValue)
Parameters
valueushortushort to set the flag value on.
positionintThe starting bit position where the flag will be set.
lengthintThe number of bits representing the flag value.
flagValueushortThe new value to set for the specified flag.