R
Ray Mitchell
Hello,
I need to be able to interpret the bit pattern in a 32-bit unsigned int as
if it represents 32-bit type float. I obviously can't simply assign the
unsigned int object to a float object because the type conversion would
change the bit pattern. In C/C++ this is an extremely trivial operation,
which I would typically do using one of the following:
int i = some pattern;
float f;
// The simplest solution
f = *(float *)&i;
// Another solution
union { int iu; float fu; } u;
u.iu = i;
f = i.fu;
However, in C# there are no unions, and pointers result in unmanaged code.
Is there a trivial way to accomplish what I want in C#?
Thanks,
Ray
I need to be able to interpret the bit pattern in a 32-bit unsigned int as
if it represents 32-bit type float. I obviously can't simply assign the
unsigned int object to a float object because the type conversion would
change the bit pattern. In C/C++ this is an extremely trivial operation,
which I would typically do using one of the following:
int i = some pattern;
float f;
// The simplest solution
f = *(float *)&i;
// Another solution
union { int iu; float fu; } u;
u.iu = i;
f = i.fu;
However, in C# there are no unions, and pointers result in unmanaged code.
Is there a trivial way to accomplish what I want in C#?
Thanks,
Ray