Edit a double's bits

I have an array of 4 chars that I want to convert into a double.

This code works in “normal” C++ but not with the Arduino:

double d = 0.0;
    for (int i = 0; i < 4; i++) {
      char *p = &d + i;
      p = data[i];

It says “cannot convert ‘*double’ to ‘*char’”.

Any other idea how to do this?

This is a little bit ambiguous. Does the array of 4 chars contain a text string that you want converted to a double? Or does it contain binary data that you want converted to a double, and if so, is it in big-endian or little-endian binary format?

I have a double value that is stored in a byte array, then sent from one device to another and I want to reassemble the original double value out of the byte array.

This is how it is stored:

char data[4];
int length = 4;
double d = 13.37;
for (int i = 0; i < 4; i++) {
	char *pb = &d + i;
	char b = *pb;	
	data[i] = b;

I think it can be done with type casting.

Try this:

char data[4];
double originald = 13.37;
double reconstrictedd;

  *(double *) data = originald;       // data[] now has the binary representation of originald
  reconstructedd = *(double *) data;  // reconstructedd now has the same

Why not use a union on both ends?

I got this solved by using long instead of double. I just multiply it by 100 before sending it and then divide it by 100 after receiving.