Float in Byte umwandeln

In ein Byte gar nicht. Ein int hat 2 Bytes. Ein float hat 4 bytes.

int -> 2 Bytes:

int i = 1000;
byte low = lowByte(i);
byte high = highByte(i);

oder:

byte low = i;
byte high = i >> 8;

2 Bytes -> int

byte low = 10;
byte high = 20;
int i = word(high, low);

oder:

int i = (high << 8) | low;

float -> byte array:

float f = 123.45;
byte* bytes = (byte*)&f;

Das ist ein Zeiger auf Bytes, d.h. ein Array aus 4 Bytes (da float eben 4 Bytes hat). Du kannst z.B. bytes[0] machen oder mit einer for-Schleife darüber iterieren

byte array -> float:

float f = *(float*)bytes;

Alternativ geht bei sowas auch eine union aus einem byte Array und dem Wert:

union floatUnion { float f; byte b[4]; };
union intUnion { int i; byte b[2]; };

Dann eine Instanz der union erstelllen und man kann mit .i, .f und .b auf die Werte zugreifen. Da die sich den gleichen Speicher teilen, wird dann automatisch der jeweils andere Wert mitgeändert.