Algotithm to Convert 4 byte Hex to 32 bit float

 I really struggled hard to find out some sorts of algorithm to convert 4 hex bytes to 32 bit float for my requirement on some analysis of MODBUS protocol. I didn’t find it and it tok me nearly 2 days to design this. Here is the algorithm.. float ModbusRead(byte id,byte msbAddress,byte lsbAddress,byte msbCrc,byte lsbCrc){ num=1.00; Serial.write(id); Serial.write(0x03); Serial.write((byte)msbAddress); Serial.write((byte)lsbAddress); Serial.write((byte)0x00); Serial.write(0x02); Serial.write(msbCrc); Serial.write(lsbCrc); delay(1000); for(i=0;i<9;i++) { if(!Serial.available()) { for (int x=0;x < 9;x++) { reply[x]=0x00; } while(Serial.available()){} break; } reply[i]=Serial.read(); } while(Serial.available()){} if((reply[3] & 0x80)!=0) num=num*-1; reply[3]=reply[3]<<1; if((reply[4] & 0x80)!=0x00)…

Read More