Hy,

I'm trying to convert a float number to a uint16_t[2], according the IEEE 754 format.

For example, I manage to do the contrary :

Qt Code:
  1. double uint16t2double(uint16_t* buff)
  2. {
  3. uint32_t test32 = 0;
  4. test32 = buff[0];
  5. int i;
  6. double resultat;
  7.  
  8. test32 = test32 << 16;
  9.  
  10. test32 = test32 + buff[1];
  11.  
  12. char sign;
  13. signe = test32 >> 31;
  14.  
  15. unsigned char expo;
  16. expo = (test32 & 0x7F800000) >> 23;
  17. expo -= 127;
  18.  
  19. uint32_t mantissa = (test32 & 0x7FFFFF);
  20. float m = 1;
  21. for(i=1; i<=23; i++) {
  22. if((mantissa & 0x400000) != 0) {
  23. m += pow(2, -i);
  24. }
  25. mantissa = mantissa << 1;
  26. }
  27.  
  28. result = pow((double)2,(double)expo);
  29. if(sign)
  30. result = -1*result * m;
  31. else
  32. result = result * m;
  33.  
  34. return result;
  35. }
To copy to clipboard, switch view to plain text mode 

Can anyone help me ?

PS: I'm new on forum, please excuse me if my message is not in the proper section and my explanations too succinct.