ASCII to float
Hi,
if I have a string say C203145B (32-bit) I want to convert it to a float My attempt was long temp; float ret; long *cast; cast = (long *) &ret; unsigned int idx = DataIndex * 8; temp = (long) AsciiToHex (m_pData[idx]) << 28 | (long) AsciiToHex (m_pData[idx+1]) << 24 | etc *cast = temp; return ret; it is working well in Windows but return a small fraction number in Linux.... Is it some big/small endian problems here? Thanks Jack |
Code:
#include <string.h> double value = 3254981723.000000 |
How about this?
union hex2str{ float f; char ch[4]; } h2s; strcpy(ret,h2s.ch); printf("%f",h2s.f); You may have to flip the ch[0] with ch[3], ch[1] with ch[2] depending on your system's byte order. |
Thanks for waking me up.
Jack |
All times are GMT -5. The time now is 11:36 PM. |