PacketDotNet库定义了一个结构UInt128。请参见:
如何在C#中将此类型转换为简单的字节数组?
发布于 2021-01-21 21:19:19
可以将其强制转换为BigTnteger,然后调用ToByteArray(),如下所示。
var number = new Uint128();
((BigInteger)number).ToByteArray();发布于 2021-01-21 21:17:53
看起来您将其赋给了一个BigInteger变量,并对其使用了ToByteArray()方法。
UInt128 n128 = 12345;
BigInteger bi = (BigInteger)n128;
byte[] ba = bi.ToByteArray();发布于 2021-01-21 21:20:47
我也发现了另一种可能性:
public static unsafe byte[] GetBytesFromUInt128(this UInt128 value)
{
byte[] numArray = new byte[16];
fixed (byte* numPtr = numArray)
*(UInt128*) numPtr = value;
return numArray;
}https://stackoverflow.com/questions/65828190
复制相似问题