So I have an unsigned integer Q with the value of 0xfccd11c0.
When I print it with printf("%i", Q); I get -53669440 which is the signed integer representation of 0xfccd11c0 so I get it.
But when I print it with printf("%i", (double)Q); I get 939524096. I DO know that in order to print a double value you need to use %f as the string format, but still, what happens when converting to double that is causing that value to be printed?
Q is 4241297856
(double)Q has 64-bit IEEE-754 representation 0x41EF99A238000000
In little-endian, the lower 4 bytes of this occupy the same space as (int)Q would.
0x38000000 is 939524096
Handy online converter: http://babbage.cs.qc.edu/courses/cs341/IEEE-754.html
Using wrong format specifier in function such as printf triggers undefined behaviour; in which case anything could happen.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With