Click to See Complete Forum and Search --> : How to access a byte within a double


Antri
August 1st, 2002, 04:43 AM
How can I access Bytes (8) in a double Variable. I need to access all 8 Bytes of a double. I need to convert each Byte of the double to an Hex-Value (String).

stober
August 1st, 2002, 04:49 AM
double value = 123.456F;
char* ptr = (char *)&value;

Antri
August 1st, 2002, 05:01 AM
But how can I access for example the 3rd Byte?

stober
August 1st, 2002, 05:21 AM
double value = 123.456F;

unsigned char* ptr = (unsigned char *)&value;

// now you can treat the double as if it were any other array of char bytes

unsigned char third_byte = ptr[2];