title: Convert from char array to 16bit signed int and 32bit unsigned int
body: <p>I'm working on some embedded C for a PCB I've developed, but my C is a little rusty!</p>
  
  <p>I'm looking to do some conversions from a char array to various integer types.</p>
  
  <p>First Example:</p>
  
  <pre><code>[input]        " 1234" (note the space before the 1)
  [convert to]   (int16_t) 1234
  </code></pre>
  
  <p>Second Example:</p>
  
  <pre><code>[input]        "-1234"
  [convert to]   (int16_t) -1234
  </code></pre>
  
  <p>Third Example:</p>
  
  <pre><code>[input]        "2017061234"
  [convert to]   (uint32_t) 2017061234
  </code></pre>
  
  <p>I've tried playing around with atoi(), but I don't seem to be getting the result I expected. Any suggestions?</p>
  
  <p>[EDIT]</p>
  
  <p>This is the code for the conversions:</p>
  
  <pre><code>char *c_sensor_id = "0061176056";
  char *c_reading1 = " 3630";
  char *c_reading2 = "-24.30";
  
  uint32_t sensor_id = atoi(c_sensor_id); // comes out as 536880136
  uint16_t reading1 = atoi(c_reading1); // comes out as 9224
  uint16_t reading2 = atoi(c_reading2); // comes out as 9224
  </code></pre>