[英]how to convert ulong to rowversion
reference to converting sql server rowversion to long or ulong?参考将 sql 服务器 rowversion 转换为 long 或 ulong? i can convert SQL RowVersion to ulong by code:我可以通过代码将 SQL RowVersion 转换为 ulong:
static ulong BigEndianToUInt64(byte[] bigEndianBinary)
{
return ((ulong)bigEndianBinary[0] << 56) |
((ulong)bigEndianBinary[1] << 48) |
((ulong)bigEndianBinary[2] << 40) |
((ulong)bigEndianBinary[3] << 32) |
((ulong)bigEndianBinary[4] << 24) |
((ulong)bigEndianBinary[5] << 16) |
((ulong)bigEndianBinary[6] << 8) |
bigEndianBinary[7];
}
Now, I am faced with a problem, how to convert ulong to byte [8]?现在,我面临一个问题,如何将 ulong 转换为 byte [8]? I save the value of rowversion to a file, then read it and use it to make the query.我将 rowversion 的值保存到一个文件中,然后读取它并使用它来进行查询。 the query parameter should be byte[], not ulong.查询参数应该是byte[],而不是ulong。 otherwise, there is an error will be raised.否则,将引发错误。
i got an answer from BigEndian.GetBytes Method (Int64)我从BigEndian.GetBytes Method (Int64)得到了答案
thanks all.谢谢大家。
public static byte[] GetBytes(this ulong value)
{
return new[]
{
(byte)(value >> 56),
(byte)(value >> 48),
(byte)(value >> 40),
(byte)(value >> 32),
(byte)(value >> 24),
(byte)(value >> 16),
(byte)(value >> 8),
(byte)(value)
};
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.