Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I print a C double bit-by-bit to see the low-level representation?

Tags:

c

double

bit

I want to learn how the computer represents the double type in bit, but the & and | bit operators can't use double. And memcpy(&d, &src, 8) also doesn't seem to work. Any suggestions?

like image 422
cppguy Avatar asked Oct 29 '25 22:10

cppguy


1 Answers

Here:

#include <stdio.h>
int main ()
{
    double decker = 1.0;
    unsigned char * desmond = (unsigned char *) & decker;
    int i;

    for (i = 0; i < sizeof (double); i++) {
         printf ("%02X ", desmond[i]);
    }
    printf ("\n");
    return 0;
}

You can try it: http://codepad.org/onHnAcnC


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!