46 lines
1.4 KiB
C#
46 lines
1.4 KiB
C#
namespace Aperio_Control_Centre.Aadp
|
|
{
|
|
public static class Helpers
|
|
{
|
|
public static string ByteArrayToString(byte[] ba)
|
|
{
|
|
return BitConverter.ToString(ba, 0).Replace("-", " ", StringComparison.InvariantCulture);
|
|
}
|
|
|
|
public static string ByteArrayToString(byte[] ba, int len)
|
|
{
|
|
return BitConverter.ToString(ba, 0, len).Replace("-", " ", StringComparison.InvariantCulture);
|
|
}
|
|
|
|
public static string ByteArrayToStringWithoutSpaces(byte[] ba)
|
|
{
|
|
return BitConverter.ToString(ba, 0).Replace("-", "", StringComparison.InvariantCulture);
|
|
}
|
|
|
|
public static string IntToBinaryString(int number)
|
|
{
|
|
const int mask = 1;
|
|
var binary = string.Empty;
|
|
while (number > 0)
|
|
{
|
|
// Logical AND the number and prepend it to the result string
|
|
binary = (number & mask) + binary;
|
|
number >>= 1;
|
|
}
|
|
|
|
return binary;
|
|
}
|
|
|
|
public static UInt16 GetUInt16BigE(this byte[] bytes, int startIndex)
|
|
{
|
|
return BitConverter.ToUInt16(bytes.Skip(startIndex).Take(2).Reverse().ToArray(), 0);
|
|
}
|
|
|
|
public static Int16 GetInt16BigE(this byte[] bytes, int startIndex)
|
|
{
|
|
return BitConverter.ToInt16(bytes.Skip(startIndex).Take(2).Reverse().ToArray(), 0);
|
|
}
|
|
|
|
}
|
|
}
|