Hi every one,
I am trying to do a simple calculation but not getting the answer I am expecting. I don't know whether this is the correct section of the forum, feel free to move if not.

Here is my code reading a reed witch activated by a magnet on a shaft.

I expected time = micros() - timeold; to work like this if in simple terms micros()=25 and timeold=20 then time =5
However here is a sample from my serial monitor;

rpmcount 20
micros() 8709992
timeold 8555748
time = 24032

according to my calculation time should = 154244

Unfortunately I can't seem to copy paste the serial monitor results but all the readings follow the same pattern

I would very much appreciate some help. Do calculations have to done in hex or binary?
Thank's
EDIT have now been able to get all the readings from the serial monitor

rpmcount20
micros8072928
timeold 0
Time 12552
rpmcount20
micros8196636
timeold 8073820
Time 58140
rpmcount20
micros8308436
timeold 8197832
Time 45924
rpmcount20
micros8416472
timeold 8309628
Time 42168
rpmcount20
micros8554604
timeold 8417668
Time 6716
rpmcount20
micros8709992
timeold 8555748
Time 24032
rpmcount20
micros9081688
timeold 8711192
Time 43676
rpmcount20
micros9776944
timeold 9082892
Time 3955

Time is passing as your sketch runs. You are calling micros() twice and expecting to get the same answer - as you can see, you don't, because 960 microseconds have passed. If that's what you want, store micros in a variable and use that for the print and the subtraction.

First a very big thank you guys. And yes I should of formatted the output.

I have done as you suggested wildbill and have got accurate readings.

I intended taking 20 divided by time and multiplying by 60000000 to get RPM however when I divide 20 by time I get 0 I will post code and output tomorrow as the pc linked to Arduino has no internet connection and keyboard. Also my GF thinks it a bit strange that I keep going to work and back every 10 minuets.

I intended taking 20 divided by time and multiplying by 60000000 to get RPM however when I divide 20 by time I get 0

Integer maths is different from floating point maths. 20 divided by anything bigger than 20 is zero (the integer part of the float). You need to plan your calculation carefully. In this case try dividing 60000000 by time and multiplying by 20 (should be the same equation).