-1

I have a uint8 vector (in a IEEE 32 float number), with the size of 4, and I want to convert to a float64, What is the best way to do this in C++/C?

I am doing float a=*(float *) my_pointer, however my compiler is using a float64, which creates a wrong conversion.

Thanks

macfij
  • 3,093
  • 1
  • 19
  • 24
user3197577
  • 1
  • 1
  • 2
  • How is `a` declared? Can you please show complete example (a [Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve))? And *what compiler (and version of it) are you using?* – Some programmer dude Aug 07 '14 at 09:10
  • 1
    Also, is the data stored in the memory pointed to by `my_pointer` stored in the right byte order for your platform? – Some programmer dude Aug 07 '14 at 09:16
  • Oh, and lastly, what is `float32` and `float64`? There are no such types either in standard C nor C++. You have [three standard floating point types](http://en.cppreference.com/w/cpp/language/types#Floating_point_types), and none of them are named with a bit-length. – Some programmer dude Aug 07 '14 at 09:21

1 Answers1

0

You can't just do a pointer type cast, as the bit representation of uint8 and float64 are different. The best you can do is to do a value cast

Zennichimaro
  • 5,236
  • 6
  • 54
  • 78
  • 1
    If the memory pointed to by `my_pointer` (in the OPs example) contains a `float` then the OP can indeed cast to a `float*` and then dereference. That `my_pointer` is actually declared as e.g. `char*` doesn't matter, just the contents of the data pointed to. – Some programmer dude Aug 07 '14 at 09:15