I\'m getting the hexadecimal values of range 0x0000 to 0x01c2 from BLE to my phone a as String
. In order to plot it in a graph, I have to convert it into
Your value isn't a hex representation of an IEEE-754 floating point value - it's just an integer. So just parse it as an integer, after removing the leading "0x" prefix:
public class Test {
public static void main(String[] args) {
String text = "0x009a";
// Remove the leading "0x". You may want to add validation
// that the string really does start with 0x
String textWithoutPrefix = text.substring(2);
short value = Short.parseShort(textWithoutPrefix, 16);
System.out.println(value);
}
}
If you really need a double
elsewhere, you can just implicitly convert:
short value = ...;
double valueAsDouble = value;
... but I'd try to avoid doing so unless you really need to.