Without going into too many details, I have two embedded systems, none of which can use the floating point library. Between them is a mobile application where some calculations are performed. One calculation should maintain accuracy. This value is sent to the client via Bluetooth, as an array of bytes. When it is received, I save it as uint32. Then this value is again used in conjunction with a mobile application where accuracy is required. There is no problem because I can use the Java ByteBuffer class. The problem is that I also need to share this value with the Z80 microprocessor as with uint8, because it is transmitted via UART and used as an ADC counter (0-255), so it loses accuracy (but it is not needed at this end).
So, I am doing this in my mobile application using Java:
int bits = Float.floatToIntBits(fAdcCount);
byte[] b = new byte[4];
b[0] = (byte)(bits & 0xff);
b[1] = (byte)((bits >> 8) & 0xff);
b[2] = (byte)((bits >> 16) & 0xff);
b[3] = (byte)((bits >> 24) & 0xff);
bthen sent with the BLE characteristic to the BLE microcontroller. The BLE microcontroller then reads this buffer as a 32-bit little-endian word and stores it in uint32. Looking at this uint32in the debugger, the correct values are displayed, and, as I said above, I can return this one uint32back to the byte array and send it to the mobile application and read it using the Java ByteBuffer class. This works fine, I get the correct floating point value.
The problem is that I need the integer part of this floating point representation to send to the Z80 microprocessor via UART as uint8, because it is used as an ADC counter from 0 to 255.
, , uint32 ( ), uint8 ? , 0 255, 255,0 .
, :
uint32 fValue = 0x43246ADD; // = 164.417...
float?:
uint8 result = 164;