As originally stated, the max UINT64 is 2^64-1, period.
Ah except you forgot one thing. The data types being used cannot represent negative numbers. In the theoretical case you gave, -96 would be represented as 4 in your unsigned type.count1 = 98
count2 = 2
diff = 2-98 = -96
actual diff = 4...But only if I know that the size of the counter is 100...and I don't know the size of the counter...
A better example is where 255 is the max. Take finish = 5, start = 250. Finish-start = 5-250 = -245. Now lets put that into a byte. The lowest 8 bits are: 00001011. Viola that equals 10.
Basically it is always safe to directly subtract two unsigned numbers that are based on a timer to get the correct answer. It only fails when the duration really does exceed the maximum value of the timer.
My homepage
Advice: Take only as directed - If symptoms persist, please see your debugger
Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"
00001011 = 0x0B = 11Originally Posted by iMalc
Else, how i personaly see unsigned integer substraction, is "substract the 2 numbers and forget about the remaining burrow". Example
You can also add the first term with the opposite of the second term. This is how processors implements substraction. ExampleCode:0 5 - F A 1 1 // burrow line ----- 0 B
I'm just throwing out this extra information for people who could be interested.Code:F A --- // 15 complement 0 5 --- // + 1 (Two complement) 0 6 0 5 + 0 6 ----- 0 B