Voltage from analog input pin

In some tutorials, like ones for the TMP36 sensor, in the code it says to use this line of code to covert the analog reading from an analog input pin to voltage:

voltage = (reading/1024) * 5

But shouldn't it be 1023 and not 1024? For example if you have 5 volts going to the pin, you would get a reading of 1023. But (1023/1024)*5 is about 4.99, not 5. So, should it be 1023 or 1024?

It should be 1024. The max read on the adc is actually that 4.95 value.

Plus since 1024 is a power of 2, the compiler can optimize that expensive divide operation into a simple bitshift.

OK, that makes sense. Thanks!

Isaac100: voltage = (reading/1024) * 5

I hope they warn you that if "reading" is an integer you are going to get nothing but 0 because of integer math. If you want a floating-point answer you should probably use: float voltage = (reading * 5) / 1024.0;