In C I will do this to convert float representation of number into DWORD. Take the value from the address and cast the content to DWORD.
dwordVal = *(DWORD*)&floatVal;
So for example 44.54321
will become 0x42322C3F
.
How can I do the same in C#
?
*(DWORD*)&floatVal
is the wrong way to do it in C as it breaks strict aliasing rules that C compilers rely on for optimisation. Correct ways involve a union (see C99tc3 footnote 82) ormemcpy()
. – Olympiaolympiad