7 Replies Latest reply on Jan 18, 2008 10:55 PM by 807603

    How to take a negative hex double number into a Double variable?

      Hi all,

      I've got the problem of taking a string representing a negative double hex number like BFF0000000000000 (which is -1 in decimal) to a double type variable. Converting positive double hex numbers works fine, but as soon as i try to convert any negative number my program throws an exception.
      conversion tool:

      I had to do this conversion method for float too, and noticed that in order to convert negative numbers too i had to make the parse with a higer type (long):

      public static float hexToFloat(String hexValue)
      float floatVal= 0.0f;

      // Parse string interpreting data as a hex number into an int.
      int decimalValue = (int)Long.parseLong(hexValue,16);

      // Reinterpret the int variable's bits as a float type.

      return floatVal;

      But in the case of Double there is no higher type, any suggestions?.

      Thanks in advance!