title: How to convert a 4-byte "string" to an uint32_t?
body: <p>Basically, I have a byte-string of data like: <code>\x00\x00\x00\x00 \x08\x00\x00\x00 \x05\x00\x00\x00</code> (spaces are used only for visibility, there are no space bytes in the actual byte-string). The data is little-endian.</p>
  
  <p>Now, I need to extract the second 4-byte group (<code>\x08\x00\x00\x00</code>, which is <code>128</code>) and turn them it an unsigned long. So, <code>uint32_t</code> type.</p>
  
  <p>Basically, what I'm doing is: <code>moveBlock(&amp;gdata-&gt;str[4], &amp;second_group, 4);</code></p>
  
  <p>Where <code>moveBlock</code> is a macro: <code>#define moveBlock(src,dest,size) memmove(dest,src,size)</code>.
  I use the macro because I personally prefer that order of parameters, if someone's wondering.</p>
  
  <p><code>gdata-&gt;str</code> is a pointer to a <code>gchar *</code>(<a href="http://developer.gnome.org/glib/2.30/glib-Basic-Types.html#gchar" rel="nofollow">ref. here</a>)
  and gdata is a <code>GString *</code>(<a href="http://developer.gnome.org/glib/2.30/glib-Strings.html#GString" rel="nofollow">ref. here</a>).
  <code>second_group</code> is defined as an <code>uint32_t</code>.</p>
  
  <p>So, this works <em>sometimes</em>, but not always. I honestly don't know what I'm doing wrong!</p>
  
  <p>Thanks!</p>
  
  <hr>
  
  <p>P.S: The code it a bit lengthy and weird, and I don't think that going through it all would be relevant. Unless someone asks for it, I won't unnecessarily clutter the question</p>