本文整理汇总了C#中Slice.ReadUInt64BE方法的典型用法代码示例。如果您正苦于以下问题:C# Slice.ReadUInt64BE方法的具体用法?C# Slice.ReadUInt64BE怎么用?C# Slice.ReadUInt64BE使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Slice
的用法示例。
在下文中一共展示了Slice.ReadUInt64BE方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ParseDouble
internal static double ParseDouble(Slice slice)
{
Contract.Requires(slice.HasValue && slice[0] == FdbTupleTypes.Double);
if (slice.Count != 9)
{
throw new FormatException("Slice has invalid size for a Double");
}
// We need to reverse encoding process: if first byte < 0x80 then it is negative (bits need to be flipped), else it is positive (highest bit must be set to 0)
// read the raw bits
ulong bits = slice.ReadUInt64BE(1, 8); //OPTIMIZE: inline version?
if ((bits & 0x8000000000000000UL) == 0)
{ // negative
bits = ~bits;
}
else
{ // postive
bits ^= 0x8000000000000000UL;
}
// note: we could use BitConverter.Int64BitsToDouble(...), but it does the same thing, and also it does not exist for floats...
double value;
unsafe { value = *((double*)&bits); }
return value;
}
示例2: ParseInt64
internal static long ParseInt64(int type, Slice slice)
{
int bytes = type - FdbTupleTypes.IntBase;
if (bytes == 0) return 0L;
bool neg = false;
if (bytes < 0)
{
bytes = -bytes;
neg = true;
}
if (bytes > 8) throw new FormatException("Invalid size for tuple integer");
long value = (long)slice.ReadUInt64BE(1, bytes);
if (neg)
{ // the value is encoded as the one's complement of the absolute value
value = (-(~value));
if (bytes < 8) value |= (-1L << (bytes << 3));
return value;
}
return value;
}