How to convert Decimal Value (Temperature) to 16 bit hexadecimal in java?
input : -54.9
Expected Result : 0x8225
I have reverse code for it where i am converting 16 byte hexadecimal to Decimal Value (Temperature).
private static double hexDataToTemperature(String tempHexData) {
String tempMSBstr = tempHexData.substring(0, 2);
String tempLSBstr = tempHexData.substring(2, 4);
int tempMSB = Integer.parseInt(tempMSBstr, 16);
int tempLSB = Integer.parseInt(tempLSBstr, 16);
int sign = 1;
if (tempMSB >= 128) {
tempMSB = tempMSB - 128;
sign = -1;
}
Float f = (float) (sign * ((float) ((tempMSB * 256) + tempLSB) / 10));
return Double.parseDouble("" + f);
}