This is a little experiment on how does a SAR ADC work.
A register, a DAC, a comparator and some control logic make an ADC. To perform a conversion, a binary search is performed. Bits in the register are turned on consecutevely from most significant bit to least significant one. If the voltage at the DAC output is higher than the voltage ADC is digitizing, the bit is turned off, if it’s lower, the bit is left on.
What I don’t mention in the video is how accuracy of resistors is important and how different kinds of errors creep in, but it’s a very broad topic on itself. Suffice to say that resistors should be as accurate as possible to get a linear response with low offset and gain errors.
One more thing to mention is that usually there is a so called “sample and hold” capacitor at the “unknown voltage” input of ADC where the voltage is sampled before the conversion so that rapidly changing input does not affect the reading.
This is schematic and Arduino code if someone wants to try it themselves.