A microcontroller reads an analog input using a 12-bit ADC with a digital output range of 0–4095.
In embedded firmware, ADC readings are commonly converted into physical units using fixed-point arithmetic to avoid floating-point overhead and to ensure deterministic behavior. A common pattern is to compute a scale factor at compile time and apply it at runtime using integer math.
Your task is to compute an ADC-to-microvolts scale factor at compile time using a constexpr function, and then use it at runtime to convert an ADC reading into microvolts (µV).
Task Requirements
constexpr function named computeScale.It must compute microvolts per ADC count using the formula:
(maxVoltage_mV * 1000) / maxAdc Define a constexpr int32_t constant named SCALE_UV by calling:
computeScale(4095, 3300)
x, representing the ADC digital value.Compute the voltage in microvolts using:
voltage_uv = x * SCALE_UV
Input Format
x representing the ADC digital valueOutput Format
Example 1
Input:
1000 Output:
805000
Example 2
Input:
4095 Output:
3296475
Constraints
0 ≤ x ≤ 4095maxAdc = 4095maxVoltage_mV = 3300 (3.3 V reference)int32_t)float, double) is allowedSCALE_UV must be evaluated at compile time
Input
0
Expected Output
0