It should be noted that this is not technically legal C++. Compilers generally will allow it, but it’s not legal according to the C++ standard, since you’re accessing a union member that is not active.
C++20 got its own “BitsTo” function in std::bit_cast, which can convert the bits of any trivially copyable object to those of another trivially copyable object of the same size.