Roy*_*mir 11 .net c# datetime .net-4.0
我看了DateTime Equals的实现:
public bool Equals(DateTime value)
{
return (this.InternalTicks == value.InternalTicks);
}
Run Code Online (Sandbox Code Playgroud)
然后看看internalticks
internal long InternalTicks
{
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
get
{
return (((long) this.dateData) & 0x3fffffffffffffffL);
}
}
Run Code Online (Sandbox Code Playgroud)
然后我注意到这个数字: 0x3fffffffffffffffL
这是: 4611686018427387903
但更有趣的是它的二进制表示:
00111111 11111111 11111111 11111111 11111111 11111111 11111111 11111111
^^
||
Run Code Online (Sandbox Code Playgroud)
请注意箭头
我可以理解是否只有左箭头0
(正面表示)
但为什么第二个0
呢?
另外,为什么我都希望它&
与一个1111....
数字?如果我想要显示5
我不必做5 & 1
,只需5.
有帮助吗?
您可以从参考源获取此类信息.dd/ndp/clr/src/bcl/system/datetime.cs中最相关的声明:
private const UInt64 TicksMask = 0x3FFFFFFFFFFFFFFF;
private const UInt64 FlagsMask = 0xC000000000000000;
private const UInt64 LocalMask = 0x8000000000000000;
private const Int64 TicksCeiling = 0x4000000000000000;
private const UInt64 KindUnspecified = 0x0000000000000000;
private const UInt64 KindUtc = 0x4000000000000000;
private const UInt64 KindLocal = 0x8000000000000000;
private const UInt64 KindLocalAmbiguousDst = 0xC000000000000000;
private const Int32 KindShift = 62;
Run Code Online (Sandbox Code Playgroud)
注意Kind值如何映射到这两个位.
public DateTime(long ticks, DateTimeKind kind) {
// Error checking omitted
//...
this.dateData = ((UInt64)ticks | ((UInt64)kind << KindShift));
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1134 次 |
最近记录: |