All submissions

Float to Bytes Type Punning

#include<iostream>
#include<iomanip>
#include<cstdint>
using namespace std;

union FloatByte
{
    float f;
    uint8_t bytes[4];
};
int main()
{
    float val;cin>>val;
    FloatByte u;
    u.f = val;

    cout<<hex<<uppercase<<setfill('0');
    for(int i=0;i<4;i++)
    {
        cout<<setw(2)<<(int)u.bytes[i]<<" ";
    }
}
Loading...

Input

1

Expected Output

00 00 80 3F