Hello, i made a robot, and i want to know in how long he runs through a specific distance.
i use :
startTime = System.DateTime.Now.Ticks;
....
ticks = (int)(System.DateTime.Now.Ticks - startTime) >> 1;
microSeconds = ticks / TicksPerMicrosecond;
it is the best solution ?
and i want to know what is the : β>>1β ? in the line :
ticks = (int)(System.DateTime.Now.Ticks - startTime) >> 1;
thx
Mike
May 25, 2013, 2:50pm
2
1 is a bit shift of one bit. It is a divide by two.
I think the code is attempting to convert the 100 nanosecond ticks into microseconds, but the code would be wrong since the shift of one bit is a binary divide not a decimal divide.
1 Like
i forgot this :
const int TicksPerMicrosecond = (int)TimeSpan.TicksPerMillisecond / 1000;
and so, if i want the real time value, i have to delete the β>>1β ?
@ Tirmit - You can look at one of several βstopwatchβ entries in Codeshare. Iβve got a barebones one there.
thanks ! it works very well