Hallo
habe versuch eine Fuktion zu erstellen wo float in Byte wandelt und die Bytes dreht.
Bei 1. Habe ich es in der Loop schleife versucht. ergebis 66246230102.
Bei 2. Fabe ich versucht dies in eine funktion zu packen. ergebniss 2550254118.
Was mache ich bei 2. Falsch ?
#include <SPI.h>
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
}
void loop() {
// Float
float Zahl1=123.45;
Serial.println(Zahl1 );
// 1.Float in Byte umwandeln
byte* bytes = (byte*)&Zahl1;
// 1.Byte drehen
byte bigEndian[4];
bigEndian[0] = bytes[3];
bigEndian[1] = bytes[2];
bigEndian[2] = bytes[1];
bigEndian[3] = bytes[0];
Serial.print(bigEndian[0]);
Serial.print(bigEndian[1]);
Serial.print(bigEndian[2]);
Serial.println(bigEndian[3]);
delay(1000);
byte* b = S7Float_to_Byte(Zahl1);
Serial.print(b[0]);
Serial.print(b[1]);
Serial.print(b[2]);
Serial.println(b[3]);
delay(2000);
}
// 2.Funktion Float in Byte, Byte drehen
byte* S7Float_to_Byte( const float inFloat )
{
byte* retVal;
byte* bytes = (byte*)&inFloat;
byte bigEndian[4];
bigEndian[0] = bytes[3];
bigEndian[1] = bytes[2];
bigEndian[2] = bytes[1];
bigEndian[3] = bytes[0];
return retVal;
}