#include <iostream>
#include <iomanip>
#include <cstdint>
using namespace std;
union FloatBytes {
float f;
uint8_t bytes[4];
};
int main() {
float val;
cin >> val;
FloatBytes u;
u.f = val;
cout << hex << uppercase << setfill('0');
for (int i = 0; i < 4; i++) {
cout << setw(2) << (int)u.bytes[i] << " ";
}
return 0;
}
Solution Details
👉 In simple words: The union lets us “peek under the hood” of a float and see its raw bytes.
Significance for Embedded Developers
Input
1
Expected Output
00 00 80 3F