return result;
}
- public static byte[] BEBytes(ushort n)
- {
- var resultBytes = BitConverter.GetBytes(n);
-
- Array.Reverse(resultBytes);
-
- return resultBytes;
- }
-
- public static byte[] BEBytes(uint n)
- {
- var resultBytes = BitConverter.GetBytes(n);
-
- Array.Reverse(resultBytes);
-
- return resultBytes;
- }
-
- public static byte[] BEBytes(ulong n)
- {
- var resultBytes = BitConverter.GetBytes(n);
-
- Array.Reverse(resultBytes);
-
- return resultBytes;
- }
-
-
- public static ushort BEBytesToUInt16(byte[] bytes)
- {
- if (bytes.Length < sizeof(ushort))
- {
- Array.Resize(ref bytes, sizeof(ushort));
- }
- if (bytes.Length != sizeof(ushort))
- {
- throw new InteropException("Array size doesn't match the ushort data type.");
- }
-
- Array.Reverse(bytes);
-
- return BitConverter.ToUInt16(bytes, 0);
- }
-
- public static uint BEBytesToUInt32(byte[] bytes)
- {
- if (bytes.Length < sizeof(uint))
- {
- Array.Resize(ref bytes, sizeof(uint));
- }
- else if (bytes.Length != sizeof(uint))
- {
- throw new InteropException("Array size doesn't match the uint data type.");
- }
-
- Array.Reverse(bytes);
-
- return BitConverter.ToUInt32(bytes, 0);
- }
-
- public static ulong BEBytesToUInt64(byte[] bytes)
- {
- if (bytes.Length < sizeof(ulong))
- {
- Array.Resize(ref bytes, sizeof(ulong));
- }
- else if (bytes.Length != sizeof(ulong))
- {
- throw new InteropException("Array size doesn't match the ulong data type.");
- }
-
- Array.Reverse(bytes);
-
- return BitConverter.ToUInt64(bytes, 0);
- }
-
public static byte[] HexToArray(string hex)
{
int nChars = hex.Length;