Given a 32-bit hex like 0x7f000002, how do I get the full value of this number printed in binary without using bitset or defining any float variables to use union?
I know that it is supposed to display
+10000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.0 for this particular 32-bit hex number.
But I don't know how to get there without using those 2 aforementioned function/variable.
You can appeal directly to what the bits in a floating point number mean: https://en.wikipedia.org/wiki/Single-precision_floating-point_format
The last 23 bits store the mantissa, and the eight bits before store the biased exponent (with the one bit before that being the signbit). The number is essentially "1.<mantissa> * 2**(<exponent> + bias)", and multiplying by a power of two is essentially shifting the binary radix point, or adding zeros to the left or right in the binary string.
Taking all that into account (+ edge cases for subnormal numbers and inf and NaN), you can make this function:
Example: https://wandbox.org/permlink/9jtWfFJeEmTl6i1i
I haven't tested this thoroughly, there might be some mistake somewhere.
Since this is a weird format in the first place, there probably isn't a prebuilt solution for this.
hexfloatis close, but in hex and with binary p notation instead