The basics

Let's get started with the basics.

We'll cover the following...

Unions are rarely used in the client code, and most of the time they should be avoided.

Floating point operations: An Example

Press + to interact
#include <iostream>
using namespace std;
union SuperFloat
{
float f;
int i;
};
int RawMantissa(SuperFloat f)
{
return f.i & ((1 << 23) - 1);
}
int RawExponent(SuperFloat f)
{
return (f.i >> 23) & 0xFF;
}

However, while the above code might ...