Hey guys, I have the following packet containing the X and Y coordinates of an entity:
[66 96 5B 45] [9A D9 03 44]
X ___________Y
* they are in 32 bit float format
I did the following (read the comments):
Code:
int main()
{
const BYTE pkt[]={0x66, 0x96, 0x5B, 0x45, 0x9A, 0xD9, 0x03, 0x44};
////// *** not works: return wrong values
DWORD px = *(DWORD*)&pkt[0];
DWORD py = *(DWORD*)&pkt[4];
float fx = (float)px;
float fy = (float)py;
//////
////// *** works: it returns the correct values
float fx = *(float*)&pkt[0];
float fy = *(float*)&pkt[4];
//////
DWORD ix = (DWORD)fx;
DWORD iy = (DWORD)fy;
return 0;
}
Why one works and the other doesn't?