I looked at DateTime Equals implementation :
public bool Equals(DateTime value)
{
return (this.InternalTicks == value.InternalTicks);
}
and then look at internalticks
internal long InternalTicks
{
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
get
{
return (((long) this.dateData) & 0x3fffffffffffffffL);
}
}
And then I noticed this number : 0x3fffffffffffffffL
which is : 4611686018427387903
But more interesting is its binary representation :
00111111 11111111 11111111 11111111 11111111 11111111 11111111 11111111
^^
||
Please notice the arrows
I could have understand if only the left arrow would have been 0
( positive representation)
But why the second one is also 0
?
Also , why would i every want it to be &
with a 1111....
number ? if I want to display 5
I don't have to do 5 & 1
, just 5.
Any help?
You can get this kind of information from the Reference Source . The most relevant declarations in 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;
Note how the Kind values map to those two bits.
public DateTime(long ticks, DateTimeKind kind) {
// Error checking omitted
//...
this.dateData = ((UInt64)ticks | ((UInt64)kind << KindShift));
}
The dateData
field is used like a bit field to store multiple values in a compact format.
The top two bits store the DateTimeKind , which has one of four possible values: Unspecified, Local (internally there are two variants), or Utc. These four values can be stored in two bits.
The bottom 62 bits store the ticks. The operation x & 0x3fffffffffffffffL
is a bitwise-and operation, also sometimes called masking . It returns only the bits that correspond to the ticks.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.