Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DWORD casting to float after a simple swap?

I want to swap my float exemple: 14 D7 65 01 ----> 65 01 14 D7

The swap is easy to do. I work on a DWORD, I made my swap and then I cast my DWORD variable to float. The problem I have is that the float value is wrong. I am sure that The DWORD swap is ok and well done. I think that the cast is made badly. Any help is more than welcome! Thank you in advance!

Here is the core of the code:

    DWORD value = 0x713D2242; 
    value =(LOWORD(value)<<16)+ HIWORD (value); 
    float fvalue = (float)value;
like image 283
Hassen Avatar asked Feb 24 '23 09:02

Hassen


1 Answers

I donot know why but I found a solution from a book which casting a float number to a DWORD number:

float f = ...;
DOWRD dw;
dw = *((DWORD*)&F);
like image 86
james.wong Avatar answered Feb 28 '23 15:02

james.wong