add remote update

This commit is contained in:
2025-04-27 21:53:02 +08:00
parent f35a295af2
commit 3f77a1a426
6 changed files with 480 additions and 64 deletions

View File

@@ -44,12 +44,12 @@ namespace Common
}
/// <summary>
/// 二进制字节数组转成整数
/// 二进制字节数组转成64bits整数
/// </summary>
/// <param name="bytes">二进制字节数组</param>
/// <param name="isRightHigh">是否高位在右边</param>
/// <returns>整数</returns>
public static Result<ulong> BytesToNumber(byte[] bytes, bool isRightHigh = false)
public static Result<UInt64> BytesToUInt64(byte[] bytes, bool isRightHigh = false)
{
if (bytes.Length > 8)
{
@@ -59,27 +59,78 @@ namespace Common
));
}
ulong num = 0;
UInt64 num = 0;
int len = bytes.Length;
if (isRightHigh)
try
{
for (var i = 0; i < len; i++)
if (isRightHigh)
{
num += Convert.ToUInt64((UInt64)bytes[len - 1 - i] << (i << 3));
for (var i = 0; i < len; i++)
{
num += Convert.ToUInt64((UInt64)bytes[len - 1 - i] << (i << 3));
}
}
}
else
{
for (var i = 0; i < len; i++)
else
{
num += Convert.ToUInt64((UInt64)bytes[i] << ((int)(len - 1 - i) << 3));
for (var i = 0; i < len; i++)
{
num += Convert.ToUInt64((UInt64)bytes[i] << ((int)(len - 1 - i) << 3));
}
}
}
return num;
return num;
}
catch (Exception error)
{
return new(error);
}
}
/// <summary>
/// 二进制字节数组转成32bits整数
/// </summary>
/// <param name="bytes">二进制字节数组</param>
/// <param name="isRightHigh">是否高位在右边</param>
/// <returns>整数</returns>
public static Result<UInt32> BytesToUInt32(byte[] bytes, bool isRightHigh = false)
{
if (bytes.Length > 4)
{
return new(new ArgumentException(
"Unsigned long number can't over 4 bytes(32 bits).",
nameof(bytes)
));
}
UInt32 num = 0;
int len = bytes.Length;
try
{
if (isRightHigh)
{
for (var i = 0; i < len; i++)
{
num += Convert.ToUInt32((UInt32)bytes[len - 1 - i] << (i << 3));
}
}
else
{
for (var i = 0; i < len; i++)
{
num += Convert.ToUInt32((UInt32)bytes[i] << ((int)(len - 1 - i) << 3));
}
}
return num;
}
catch (Exception error)
{
return new(error);
}
}
/// <summary>
@@ -152,6 +203,12 @@ namespace Common
return (srcBits & mask) == dstBits;
}
/// <summary>
/// 获取整型对应位置的比特
/// </summary>
/// <param name="srcBits">整型数字</param>
/// <param name="location">位置</param>
/// <returns>比特</returns>
public static Result<bool> ToBit(UInt32 srcBits, int location)
{
if (location < 0)