title: C++ int or float to char array
body: <p>I'm trying to convert a integer or a float to a char array, in a specific form (programming for mbed, a micro-controller).</p>
  
  <p>The integers should be 32-bit big-endian two's complement integer
  The floats should be 32-bit big-endian IEEE 754 floating point number</p>
  
  <p>Tried a few things:</p>
  
  <pre><code>uint8_t *v;
  uint8_t valuePos = 3;
  v = (uint8_t *)datum-&gt;data.i; //I get the int or float from datum-&gt;data.i
  buff[lengthEnd++] = v[valuePos--]; //buff is the char array
  buff[lengthEnd++] = v[valuePos--];
  buff[lengthEnd++] = v[valuePos--];
  buff[lengthEnd++] = v[valuePos]; 
  </code></pre>
  
  <p>and</p>
  
  <pre><code>uint32_t i = BigEndian(datum-&gt;data.i);
  uint8_t * ptr = (uint8_t *) &amp;i;
  strcat(buff, (char *) ptr); //maybe strcat isn't a good function to use here
  lengthEnd += 4;
  </code></pre>
  
  <p>But I can't make it work, I always get some other number. What is going wrong?</p>