| ??? 08/26/08 10:09 Read: times |
#157765 - silly C question |
Hi Guys,
I have a device that sends data over RS232 to my computer. I wrote some C to log/parse/display the received data. Data comes in big endian and I'm on an intel machine. I know that 4 bytes in a particular data string are represented as an IEE 754 single precision floating point number. I currently have something like this: uint32_t *raw_data; uint32_t time; raw_data = buf; //some large buffer of data time = ntohl(*raw_data); //fix the endianness issue Now, I can correctly display the hex value for time. How do I, however, display it/convert it to a single precision floating point number? I've tried things like printf("%f", (float)time) and other such casting schemes, but nothing seems to be working as I'd like it to... Thanks, D |
| Topic | Author | Date |
| silly C question | 01/01/70 00:00 | |
| *(float*)&time | 01/01/70 00:00 | |
| Thanks!!! | 01/01/70 00:00 | |
| Here's one without wild casting: | 01/01/70 00:00 | |
| Nothing wild | 01/01/70 00:00 | |
| union misuse | 01/01/70 00:00 | |
| Not hiding cast | 01/01/70 00:00 | |
| Programmer knowledge required. | 01/01/70 00:00 | |
| Hiding of portability issue | 01/01/70 00:00 | |
Portability C | 01/01/70 00:00 |



