+1  A: 

The spec for the ADC should identify how 5V is represented in terms of your 12 bits.

I would suspect that 4095 corresponds to 5V and thus your second solution is correct. Otherwise you would never be able to identify a signal of 5V correctly.

Brian Agnew
+2  A: 

Brian's suggestion about checking ADC datasheet is ideal. BUT! Assuming your maximum voltage (5V) equates to the maximum ADC input (12-bits = 4095), the following conversion should work for you:

const float maxAdcBits = 4095.0f; // Using Float for clarity
const float maxVolts = 5.0f;      // Using Float for clarity
const float voltsPerBit = (maxVolts / maxAdcBits);

float yourVoltage = ADCReading * voltsPerBit;

A quick inspection of the math with Excel leads me to believe this is correct.

Nate
+1 divides can be expensive.
kenny
... but using floats can be expensive too.
Nate
Use fixed-point arithmetic and bit shifts instead of divides. Or better, don't convert to voltage at all and just work with the 12 bit value from the ADC and when you need to compare it to a voltage just translate the voltage to the same value on the 12-bit scale.
Stephen Friederichs
A: 

For a 12-bit value the maximum representable value is 4095, but of course there are 4096 values total (including zero). Assuming that your ADC is linear then yes, 4095 is equivalent to full scale. This is not necessarily 5V but whatever your reference voltage is equivalent to OR a value exceeding that voltage (of course).

Stephen Friederichs
A: 

How picky do you want to get? If you want to really get picky, then you should also consider that each "bin" represents a small range of values (about 1.2 mV in your case). So when you convert to a voltage value, do you want to return the voltage value of the middle of the bin, or the lower edge of the bin? That is, do you want to effectively "truncate" or "round" in the value you report?

Also, the ADC's steps are probably even (linear), but take care as to what the ADC does with the bins at the two extremities of the range. Those bins may be possibly half the width of the others. It depends on the ADC, so check the spec.

Whether this concern matters at all depends on your application.

Craig McQueen