I am trying to use printf
in order to print the binary representation of a double onto the console. Here is the code that I have so far:
#include <stdio.h>
int main()
{
double a = 4.75;
unsigned long long b = *(unsigned long long *) &a;
printf("Double a = %f (0x%x)" a, b);
}
I also tried changing it from a long long to a long instead. Here is the result that I get from doing this in gcc linux:
Double a = 4.750000 (0x0)
I'm pretty sure since my system is little endian that it is only grabbing the first 32 bits which are all zeroes. However, I'm not sure how to fix this.
I thought it might have been because long is 64 bit in linux but after testing that I got the same result again. Maybe I'm printing it incorrectly? Not sure, let me know and thanks for your time.