title: How to cast hex value to WORD, DWORD or QWORD and store the result in a double variable?
body: <p>I'm trying to cast a signed hex number to WORD, DWORD and QWORD by this way:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;inttypes.h&gt;
  
  int main(void) {
  
    printf("WORD=%d\n",  (int16_t) strtol("F123", NULL, 16));
    printf("DWORD=%d\n", (int32_t) strtol("FFFFF123", NULL, 16));
    printf("QWORD=%lld\n", (int64_t) strtol("FFFFFFFFFFFFF123", NULL, 16));
  
    return 0;
  }
  </code></pre>
  
  <p>But it returns the following:</p>
  
  <pre><code>WORD=-3805
  DWORD=2147483647
  QWORD=2147483647
  </code></pre>
  
  <p><a href="http://ideone.com/mqjldk" rel="nofollow">http://ideone.com/mqjldk</a></p>
  
  <p>But why the DWORD and QWORD castings are not returning <code>-3805</code> too?</p>
  
  <p>I mean: <code>0xFFFFF123</code> stored in a DWORD would contain <code>-3805</code> value in decimal, not <code>2147483647</code></p>
  
  <p>Expected output:</p>
  
  <pre><code>WORD=-3805
  DWORD=-3805
  QWORD=-3805
  </code></pre>
  
  <p>Do you have an bitwise alternative to do it? </p>