// 28 January 2022, Version 1, by Koepel, Public Domain
// For: https://forum.arduino.cc/t/8-bytes-to-double-conversion/952352/
// The Wokwi simulation uses Serial1 for the Raspberry Pi Pico
#define _SERIAL Serial1
const int InBytes[10] =
{
0x0000, 0x0000,
0x00C6, 0x006B, 0x0080, 0x00E8, 0x0069, 0x00F5, 0x00B0, 0x003F,
};
void setup()
{
_SERIAL.begin(115200);
_SERIAL.println("Hello, the sketch has started");
_SERIAL.print( "The sizeof(double) = ");
_SERIAL.println( sizeof( double));
// No union, just low level converting
byte myBytes[8];
for( int i=0; i<8; i++)
{
myBytes[i] = (byte) InBytes[i+2]; // take the lowest byte of every int
}
double myDouble;
memcpy( &myDouble, myBytes, 8);
_SERIAL.print( "My double = ");
_SERIAL.println( myDouble, 15);
}
void loop()
{
delay( 100);
}