I wrote a program to print out the bit pattern of a float number in C.
So I expected to receive a standard-IEEE-754 bit pattern i.e.: 1 sign bit | 8 EXP bits | 23 mantissa bits
when I got the output and put the result to an IEEE-754 converter the number was wrong. When I bit by bit reversed the order, the number was correct.
So why I'm asking is: I found a thread in which I learned that the pattern could be BYTE-WISE reversed, but nowhere I found it completely BIT-WISE reversed.
Can anyone claryfy on this, please?
Here's a Screenshot of the program, the output and the conversion result. (As you can see I put the numbers into the converter in reversed order and the result looks fine to me.)
Endianness is not the issue here, since you're using a bit-shift operator on the value of the entire object.
You simply printed out the bits in the opposite order, there is nothing more than that.
You start printing least significant bits first, and the webpage starts with most significant bits. Both variants are correct.
One a side node, the way you're interpreting the float as an int is not correct and it causes undefined behavior. You should use an unsigned integer with its width equal or greater to the width of type float, and use memcpy.