Search code examples
integersignedadc

When using signed int, does my value always start from zero?


I have been diving into and reading endless internet forums and pages trying to find an answer to this, but have had no luck, so here we are. For reference, I am using an A/Dconverter and I am changing the value of the A/Dconverter using a variable resistor plugged into ground and 5V. So when I write my C code, if I am using a signed integer--that integer being the value of the analog to dig conversion--will the value be automatically split on both sides of zero. For example, let's say I have get an 8 bit integer and I am using signed int. Because I am using signed int, will the values that I get automatically be anywhere from 0 to +255 or should I automatically receive a value that is anywhere between -128 to +127 when I move the wiper on the resistor?


Solution

  • Welcome to stackoverflow! It seems like a minor detail that you can easily test. However, most tutorials I have checked just now use 'int' rather than 'unsigned int'. One of the tutorials says the following:

    "The value that is returned and stored in x will be a value from 0 to 1023. The Arduino has a 10-bit ADC (2^10 = 1024). We store this value into an int because x is bigger (10 bits) than what a byte can hold (8 bits)."

    which makes me believe the values will be somewhere from 0-X, dependent on the amount of bits available. But as I said, this will be easily testable.