Convert hex to float

I have to convert a bit Hex string into a float. I built a vi from the following C code, but it only works on positive numbers. Any suggestions?
sample16 = (short) ((MSB << 8) | LSB);
sample = (float)sample16/32768.0;
sample*=10.0;
Attachments:
Parse Response.vi ‏13 KB

[email protected] wrote:
Hi altenbach
The data is come from flowmeter by MODBUS. 
Thanks
Hong
You are not giving us any useful information.  Look up the manual of your device.  Somewhere in there should be a definition of how the numbers are built up.
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines

Similar Messages

  • How to convert signed ascii hex to float value

    Hi,
    I have a requirement to convert IEEE ascii hex to float value.
    Following code is working for +ve float value but it didn't work for -ve.
    public static float hexToFloat(String str){
              float floatVal= 0.0f;
              int decimalValue =Integer.parseInt(str,16);
              floatVal=Float.intBitsToFloat(decimalValue );
              return floatVal;
    for example "BE4CE1E6" should return -0.20 . (i verified in http://babbage.cs.qc.edu/IEEE-754/32bit.html )
    For the above string I am getting number format exception.
    pls help me.

    The problem is the parseInt method. It can only process numbers up to 2147483647 or 7FFFFFFF. Because that method expects a signed number.
    The solution is to use Long.parseLong() instead.
    public static float hexToFloat(String str){
    float floatVal= 0.0f;
    int decimalValue =(int)Long.parseLong(str,16);
    floatVal=Float.intBitsToFloat(decimalValue );
    return floatVal;
    }

  • Convertion Hex String to 32bits Decimal floating point??

    Hi,
    I would like to know how to convert hexa like: 416b0ac3 in decimal 32bits floating-point. The result of this string is suppose to be 14.690127.
    So i must be able to do:
    From 32-bit Hexadecimal Representation To Decimal Floating-Point
    Thanks for your support
    RiderMerlin

    RiderMerlin
    You can use the typecast function to do this.
    David
    Message Edited by David Crawford on 09-06-2006 03:31 PM
    Attachments:
    Typecast to Single.jpg ‏6 KB

  • Converting string to float

    I have a decimal string "122339994" which i am trying to convert to float using Float.parseFloat. This results in incorrect value of 1.22339992E8.
    I thought for floats precsision comes into effect after decimal places.
    public static void main(String[] args) {
    String floatString = "122339994";
    float floatNumber = Float.parseFloat(floatString);
    System.out.println("Float is "+floatNumber+". Now double "+Double.valueOf(floatString));
    }

    See this API
    [Java2SE Float|http://download-llnw.oracle.com/javase/6/docs/api/java/lang/Float.html#valueOf%28java.lang.String%29]
    Note that trailing format specifiers, specifiers that determine the type of a floating-point literal (1.0f is a float value; 1.0d is a double value), do not influence the results of this method. In other words, the numerical value of the input string is converted directly to the target floating-point type. In general, the two-step sequence of conversions, string to double followed by double to float, is not equivalent to converting a string directly to float. For example, if first converted to an intermediate double and then to float, the string
    "1.00000017881393421514957253748434595763683319091796875001d"
    results in the float value 1.0000002f; if the string is converted directly to float, 1.0000001f results.
    Its better to see the Java APIs first for any information, we will get almost all the information we need from APIs
    Regards,
    Venkatesh

  • Java code to convert - Hex to Dec

    I'ld like to convert an Integer or a String from hexadecimal format to a decimal format;
    For example: 30 give 0; 50 give P and so on.
    Can any one help me sending to me a java code that do it please?
    Thanx a lot

    This doesn't convert hex to decimal, but it does convert hex to the character representation, which is what it sounds like you want. At any rate, given "30" it will print "0" and given "50" it will print "P". Also, given "P" it will print "is invalid".
            try
                int in = Integer.parseInt(s, 16);
                Character ch = new Character((char)in); // should validate range here
                System.out.println("In: " + s + ", out: " + ch);
            catch (NumberFormatException e)
                System.out.println("In: " + s + " is invalid.");
            }

  • Converting hex to dec

    Hi everybody,
    I want to join this two numbers and convert them from hex to dec. I have tried using joint and conversion but I still couldn't work it. In the following screen shot I took it suppose to be 3E8 in hex which equals to 1000 in dec. I need suggestion from you how to approach this.
    Thanks
    Solved!
    Go to Solution.

    SOBGA wrote:
    As I was reading all the answers about converting Hex to Dec,I found out that many of you are making it so complicated.To make it easier for a learner or beginner,this is what it takes:
    Open a blank VI
    Click on numeric control
    Right click on the same numeric control
    Scroll down to "Representation"
    Click on "U8"
    Go to numeric indicator and repeat step 4 and 5
    Then right click again on numeric control
    Scroll down to "Properties" and click
    Click on "Data entry",if necessary,change the minimum and maximum
    Pass to "Display format" 
    Click on "Hexadecimal" then you are done.The rest is to go on the block diagram to wire the numeric control to the numeric indicator and it works.
    You can do the same process reverse for dec to hex.But you must know that what we did for "numeric control" on (Hex to Dec) will be done to "numeric indicator" on (Dec to Hex).This same process can apply to octal and binary without the use of complicated array,string while loop and so on...
    I'm a beginner in Labview and I understand that you need to explain more to understand better.
    If you really read all of the comments, you would see that Altenbach already stated this (saying it is just a cosmetic property for the indicator).
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • Converting Hex to Integer Value

    I'm trying to convert hex code to the corresponding integer, which can then be used to display a character.
    For example I have the code.
    int i = 0xE7;
    System.out.println(i);
    System.out.write(i)This produces the output as expected with the first output outputting 231, and the second line outputting the corresponding character.
    My problem comes when trying to make it so the hex code is variable.
    For example, I receive an output of 7
    This output is then the last digit of the hex code (so i check if needs to be converted to a, b etc.) then try and combine it with the prefix 0xE to create the hex code.
    I'm not quite sure how to do this bit as I cant carry out
    num = 7;
    hex = "0xE"+num;
    int i = hex;as the last line doesn't calculate due to hex being a string.
    Many thanks for your help.

    leesto wrote:
    The char array is currently being created using:
    char [] hexchar = "0123456789ABCDEF".toCharArray();
    Look this is OK, you need to do nothing but just the following:
    // I am using the very first example you provided
    // i is the index for the char
    String hex = "0E" + hexchar;
    Integer.parseInt(hex, 16);
    System.out.println(i);

  • Convert  Hex to Dec in Numbers

    Hi,
    Can some one let me know how to Convert Hex to Dec in Numbers.
    When ever I type Hex 00E0 it will appear in the cell like this 0.00E+00 ,who do i fix this.
    Thanks
    Ashan

    -+-+-+-+-+-+-+-
    Entering the Help and Terms of Use area you will read:
    *What is Apple Discussions and how can it help me?* 

    Apple Discussions is a user-to-user support forum where experts and other Apple product users get together to discuss Apple products. … You can participate in discussions about various products and topics, find solutions to help you resolve issues, ask questions, get tips and advice, and more.
    _If you have a technical question about an Apple product, be sure to check out Apple's support resources first by consulting the application Help menu on your computer and visiting our Support site to view articles and more on our product support pages_.
    I have a question or issue—how do I search for answers? _
It's possible that your question or issue has already been answered by other members so do a search before posting a question._ On most Apple Discussions pages, you'll find a Search Discussions box in the upper right corner. Enter a search term (or terms) in the field and press Return. Your results will appear as a list of links to posts below the Search Discussions Content pane.
    -+-+-+-+-+-+-+-
    Taking care of that, you would already know the response.
    Using the really cumbersome keystring "convert AND hex" as described in the forum's help returns two entries.
    One is you question.
    The other is: http://discussions.apple.com/thread.jspa?messageID=7242325
    which gives a link to:
    http://discussions.apple.com/thread.jspa?messageID=7078123
    Yvan KOENIG (from FRANCE jeudi 24 juillet 2008 09:19:34)

  • How to convert hex string to time stamp?

    Hello everyone..
    I am currently working on a project in which I have to read the data from a unit and display that data using LabVIEW. I am using serial communication for reading the data. The read data is in hex format. 
    Now, I want to convert this hex string to a time stamp value. I am reading total 16 bytes. How to convert this hex data to a time stamp value. I have developed a VI. But I want to know that the displayed time stamp is correct or not? Or suggest me some other solution. 
    I am using LabVIEW 2011.
    Thanks & Regards,
    Manisha
    Attachments:
    Test.vi ‏7 KB

    Hi mancan,
                      As Iam using LV2009 Iam unable to open your example.Anyway for converting hex to time stamp
    Thanks as kudos only

  • Convert hex to Decimal and keep leading zeros..

    Hi,
    I hope you can help?
    How to convert hex to Decimal and keep leading zeros
    I read 002C, hex, and I want to convert it to 0044 decimal.
    sscanf (MyNum, "%4x", &DecNum); will only give me 44.
    It have been working up till I started to get leading zeros.
    We will always have a 4 digit hex input in a range
    We must have the leading 00 in this case.
    How is this best done?
    Thanks for the help
    Simon
    Solved!
    Go to Solution.

    Hi,
    I don't really understand your problem. Is this stuff what you need ?
    int main (int argc, char *argv[])
    const char MyNum[] = "002C";
    int DecNum;
    sscanf (MyNum, "%4x", &DecNum);
    printf ("%04d", DecNum);
    getchar ();
    return 0;
    "0044" appears on standard output when printf function executes...

  • Convert string to floating-point

    Hi all,
    ..very basic question, but I tryed it for hours and only received short-dumps
    <b>How can I convert a string into a floating-point number?</b>
    Kind regards,
    Stefan

    hi
    try this
    to convert  string to float.
    data : a type f,
    s type string value '1.023'.
    a = s.
    write :/ a.
    to convert float to string.
    data : a type f value '1.023',
    s type string.
    s = a.
    write : s.

  • Convert Hex to ASCII

    Is there an easy way to convert a HEX file format or string to ASCII format? It's easy to convert ASCII to HEX using using "toHexString" but how do you convert HEX back to ASCII?

    Integer.parseInt(hexString, 16);

  • Looking for VI where i can convert covert a float number to Q 11.5 representation

    looking for VI where i can convert covert a float number to Q 11.5 representation and what exactly  Q 11.5 representation means.
    Kindly help me on the same.
    Solved!
    Go to Solution.

    Appears to be right, but don't forget to round to the nearest integer.
    http://zone.ni.com/reference/en-XX/help/371361H-01/glang/round_to_nearest/
    Now is the right time to use %^<%Y-%m-%dT%H:%M:%S%3uZ>T
    If you don't hate time zones, you're not a real programmer.
    "You are what you don't automate"
    Inplaceness is synonymous with insidiousness

  • Converting Vector with Floats to float[] typecast error?

    Java Developers,
    I am able to convert my String vector to a
    String[] but just can't get the Vector with Floats to be converted to a float[] array. I have looked into google and java.sun.com Forums but still cant seem to find the answer. I would really appreciate your help!
    This is how I am making the conversion from Vector(String) to String[]:
    legendLabelsArray = new String[columnHeads.size()];
    int k=0;
    Iterator e = columnHeads.iterator();
    while(e.hasNext()){
    System.out.println("inside the enumerator");
    legendLabelsArray[k] = e.next().toString();
    System.out.println("Array elements at " + k + " are " + legendLabelsArray[k]);
    System.out.println(k++);
    How can I make something similar to work with a Vector with Floats to float[] instead of Strings?
    Thanks,
    Musaddiq
    [email protected]

    Something like this ...
    float[] floatArray = new float[vectorOfFloats.size()];
    int k=0;
    Iterator e = vectorOfFloats.iterator();
    while(e.hasNext()){
    floatArray[k] = ((Float) e.next()).floatValue();
    k++;

  • Converting HEX to FLTP

    Hi All,
      I want to convert a hex value to FLTP. How can I do it?..
    Normal covnersion rules say it is first converted to a packed number and then to floating point number giving me the wrong results.

    Hi
    As you have said that ABAP supports automatic type conversion for all the fields with the exception that you  can't assign type t to type d and vice versa.
    I feel whatever you are getting is the correct value after automatic type coversion.
    Try to use correct data types wherever possible.SAP is also recommending this.
    Abdul

Maybe you are looking for

  • Can't Find ppbus

    I am working on a package for the aur but i get this error while running cmake: /root/Desktop/piklab/src/piklab-0.15.10/CMakeFiles/CMakeTmp/CheckIncludeFiles.c:2:27: fatal error: dev/ppbus/ppi.h: No such file or directory compilation terminated. '/ro

  • How to restore files from Carbonite

    My computer crashed and I had to reinstall my software. I previously had not backed things up on Mozbackup, but Carbonite backed my files up. now, can you tell me the procedure to restore my addresses and other files from carbonite's backup?

  • Myanmar Burmese text not showing properly on Richtextbox c#

    Hello Can't get Myanmar Burmese text to display properly on Richtextbox c#, I get some boxes instead of real text, any advise ? I've already tried several fonts without success, unless there is a font, that I don't know about, or is not installed in

  • Technical Question  Gurus

    Think with me here gurus, If you were to create a video in FCP/Motion that you wanted to export for a Flash Website what would your settings be? Dimensions of the project your working in? To give you an example of a website who has implemented a vide

  • Mail cant read my new email and is very slow

    When MAC I open my Mail application it takes ages to load the inbox and NON of my 3 POP mail accounts can be read, i have the Saturn ring spinning non stop but nothing happens. This problem started yesterday morning and I am not sure if it is my ISP