Convert Floating Point Decimal to Hex

In my application I make some calculations using floating point format DBL,and need to write these values to a file in IEEE 754 Floating Point Hex format. Is there any way to do this using LabVIEW?

Mike,
Good news. LabVIEW has a function that does exactly what you want. It is well hidden though...
In the Advanced/Data manipulation palette there is a function called Flatten to String. If you feed this funtion with your DBL precision digital value you get the IEEE-754 hexadecimal floating point representation (64 bit) at the data string terminal (as a text string).
I attached a simple example that shows how it works.
Hope this helps. /Mikael Garcia
Attachments:
ieee754converter.vi ‏10 KB

Similar Messages

  • Converting Floating Point

    I am receiving numbers from a Tinius Olsen Model 290 Universal Testing System.  I made a little program to send commands to the machine and receive the responses back as strings.  For the decimal value 3.7620 I get the floating point number EDC57040.  This is obviously not correct.  The correct floating point representation is 4070C5ED, which is accomplished by swapping all the bits.  I need to know how to do this in labview, basically go from the string representation of the floating point to the correct swapped floating point.

    Here is a simple example:
    Be aware that if you have an ancient version of LabVIEW, this option (byte order) is not available and you need to swap the bytes manually. No big deal, really.
    Message Edited by altenbach on 05-08-2007 01:15 PM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    LittleEndianSGL.png ‏7 KB

  • Checking and Converting binary, octal, decimal, and hex

    Hi,
    I have a classroom project which will need to validate that data entered in a text is of a certain type with a keyListener, and then convert that value to the other 3 types.
    I know character.isDigit will handle the decimal case, and that I can then use Integer.otString methods to convert to binary, octal, and hex, but what about the other cases?
    Thanks

    OK, this isn't working. If I've already established
    that the string entered into, for example, the
    integer-only textfield is a valid integer, I should be
    able to simply use integer.parseint(s, 2) to convert
    it into binary, right?Not exactly. You should be able to use Integer.parseInt(s, 2) to return the result of converting it from binary representation. You appear to think that this affects whatever "s" refers to, which is not the case. Note also, that method returns an int which is the decimal value in question.
    When you are thinking of int variables, be careful not to think of them as "decimal" or "binary". They are neither. They are just numbers. "Decimal" and "binary" are text representations of numbers, so those concepts can only be applied to strings.
    Integer.parseInt(s, 2);
    txtBin.setText(s);So here you want to assume that the input is a string that represents a number in decimal, and you want to find the string that represents the number in binary. Like this:// convert string in decimal representation to number
    int dec = Integer.parseInt(s);
    // convert int to binary representation as string:
    String binary = Integer.toBinaryString(dec);
    // write that to the text field
    txtBin.setText(binary);You could use a one-liner to do that, but you'll need the "dec" variable to set the other text boxes.
    Rembering why I hate OO...All of what I said there is true in just about all computer languages, OO or otherwise.
    PC²

  • Floating point decimal

    Hi,
    How to get standard floating decimal number out of:
    double a = 0.0;
    double ans = (double)a+1.0/(397+658);
    the answer woulld be 9.478672985781991E-4. how to get say, 0.00094787 as double?
    please help.
    many thanks

    Or use Java 5's Formatter class (or one of its related methods), or BigDecimal class (Or some combination of any of the above.)

  • Floating Point Decimal Displays

    Hello,
       OK - now for a wierd one.  I have a Z-attribute of 0MATERIAL that is FLTP format.  When I go to SE16 and look at /BI0/PMATERIAL I can't see that field because it is FLTP.  Is there any way that I can see it in BW, or do I have to go down to the DB level?
       Thanks - will award points for helpful answer...
    Dave Knudson

    Hi Dave,
    It doesn't matter if one of the attribute of ZMATERIAL is of FLTP format. You should be able to select that field for field selection as well as in the Output.
    by default the field selection may not show all the attributes. GOTO >settings>Field for selection and give the filed name.
    While the output is displayed by default the output result width is 250 characters change the output width to max 1023 it would display all the characters.
    Assign points if useful.
    Thanks & Regards,
    Namrata

  • Profibus data type converting to floating point

    Hi, 
    Is there an efficient way to convert  the incoming data to the floating point in the NI cRIO Profibus system? 
    1) The system is : NI cRIO 9068 Controller with Comsoft profibus slave module. The lavview we are using is 2013. 
    2) We are using profibus slave example and are able to see a array of unsigned 8 bit data. Please see the Output data shown in the attachement.
    3) On the other side of profibus system, thrid party profibus master are converting floating points and tranmit the converted data to NI profibus slave. 
    Attachments:
    Screenshoot.png ‏7 KB

    If it's just a matter of converting data types once you have the data in LabVIEW, you can always manually scale and convert the data using the arithmetic functions and the "To Double Precision Float" or "To Single Precision Float" functions. You just have to know what floating point value the unsigned byte integer corresponds to. Is that what you're asking?
    If you're asking for a way to this inherently with the Profibus functions, I'm afraid I can't be of much help...
    Ryan K.

  • Floating point numbers into XML file

    Hi,
    I am a learner in Labview and I am using Labview 8.5 version.
    when I use FlattentoXML component to convert floating point numbers ( having more than 5 decimal points) into XML, the output contains alway 5 decimal points.
    But, I want exact decimal number to be displayed as XML. i.e 0.263746 should not be displayed as 0.26375 in XML.
    Do you have any suggestions ?
    Attachments:
    Float_to_XML.vi ‏7 KB

    I tested it and could not see your problem in Labview 2009. So it is perhaps a bug in your Labview version. You can use this VI as a workaround.
    Besides which, my opinion is that Express VIs Carthage must be destroyed deleted
    (Sorry no Labview "brag list" so far)
    Attachments:
    Float_to_XML[2].vi ‏8 KB

  • Floating point to binary conversion

    Hi
    I need to convert a floating point decimal number to bits.
    Eg. 0.000532 to be converted to binary(bits).
    How do I do this?

    Now if I convert that decimal number to bits(in
    the usual method of dividing by 2),will that be the
    exact binary representation of the floating point
    decimal number?You have the same bit pattern in both cases. In one it's held in a double and will be interpreted as a floating point number according to the IEEE 754 representation. In the other it's held in a long and will be interpreted according to the two's complement representation. But it's the same bitpattern.
    Note that Long has a toString method which allows you to convert the long to a String. The radix in your case is 2 for binary.

  • Converting byte from dec to hex

    Hi All,
    I'm having a problem converting byte from decimal to hex - i need the following result:
    if entered 127 (dec), the output should be 7f (hex).
    The following method fails, of course because of NumberFormatException.
        private byte toHexByte(byte signedByte)
            int unsignedByte = signedByte;
            unsignedByte &= 0xff;
            String hexString = Integer.toHexString(unsignedByte);
            BigInteger bigInteger = new BigInteger(hexString);
            //byte hexByte = Byte.parseByte(hexString);
            return bigInteger.byteValue();
        }

    get numberformatexception because a lot of hex digits cannot be transformed into int just like that (ie f is not a digit in decimal) heres some code that i used for a pdp11 assembler IDE... but this is for 16-bit 2s complement in binary/octal/decimal/hex , might be useful for reference as example though
        public static String getBase(short i, int base){
            String res = (i>=0)? Integer.toString((int)i,base)
                    : Integer.toString((int)65536+i,base) + " ("+Integer.toString((int)i,base)+")";
           StringBuffer pad= new StringBuffer();
            for(int x = 0; x < 16 - res.length() ; x++){
                pad.append("0");
            res = pad.toString() + res;
            return res;
        }

  • Floating point conversation

    Dear all,
        In a particular filed i entered value as 60.800 kg. But when i try to pick the value   i found that the value is stored in floating pont format ie 6.080000000000e+00 . Actually i need it in integer format .Is any function module available to convert floating point to integer.
    Regards
    Mahesh V

    Why use a function module?
    DATA: l_val_int type i,
          l_val_flt type f,
          l_val_pck type p decimals 2.
    l_val_flt = '6.080000000000e+00'.
    l_val_int = l_val_flt.
    l_val_pck = l_val_pck.
    matt

  • Floating point to time conversion

    Hi all,
      I need to convert floating point value to time.Any help would be gr8

    Hai,
       Define two variables,one as float & another one as time take a & b.After assigning values to a,assign a to b.Then write b.The float value will be converted into time format.
    Regards,
    Padmam.

  • 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

  • BUG: Large floating point numbers convert to the wrong integer

    Hi,
    When using the conversion "bullets" to convert SGL, DBL and EXT to integers there are some values which convert wrong. One example is the integer 9223370937343148030, which can be represented exactly as a SGL (and thus exactly as DBL and EXT as well). If you convert this to I64 you get 9223370937343148032 instead, even though the correct integer is within the range of an I64. There are many similar cases, all (I've noticed) within the large end of the ranges.
    This has nothing to do with which integers can be represented exactly as a floating point value or not. This is a genuine conversion bug mind you.
    Cheers,
    Steen
    CLA, CTA, CLED & LabVIEW Champion
    Solved!
    Go to Solution.

    Yes, I understand the implications involved, and there definetely is a limit to how many significant digits that can be displayed in the numeric controls and constants today. I think that either this limit should be lifted or a cap should be put onto the configuration page when setting the display format.
    I ran into this problem as I'm developing a new toolset that lets you convert all the numeric formats into any other numeric format, just like the current "conversion bullets". My conversion bullets have outputs for overflow and exact conversion as well, since I need that functionality myself for a Math toolset (GPMath) I'm also developing. Eventually I'll maybe include underflow as well, but for now just those two outputs are available. Example:
    I do of course pay close attention to the binary representation of the numbers to calculate the Exact conversion? output correctly for each conversion variation (there are hundreds of VIs in polymorphic wrappers), but I relied in some cases on the ability of the numeric indicator to show a true number when configured appropriately - that was when I discovered this bug, which I at first mistook for a conversion error in LabVIEW.
    Is there a compliancy issue with EXT?
    While doing this work I've discovered that the EXT format is somewhat misleadingly labelled as "80-bit IEEE compliant" (it says so here), but that statement should be read with some suspicion IMO. The LabVIEW EXT is not simply IEEE 754-1985 compliant anyways, as that format would imply the x87 80-bit extended format. An x87 IEEE 754 extended precision float only has 63-bit fraction and a 1-bit integer part. That 1-bit integer part is implicit in single and double precision IEEE 754 numbers, but it is explicit in x87 extended precision numbers. LabVIEW EXT seems to have an implicit integer part and 64-bit fraction, thus not straight IEEE 754 compliant. Instead I'd say that the LabVIEW EXT is an IEEE 754r extended format, but still a proprietary one that should deserve a bit more detail in the available documentation. Since it's mentioned several places in the LabVIEW documentation that the EXT is platform independent, your suspicion should already be high though. It didn't take me many minutes to verify the apparent format of the EXT in any case, so no real problem here.
    Is there a genuine conversion error from EXT to U64?
    The integer 18446744073709549568 can be represented exactly as EXT using this binary representation (mind you that the numeric indicators won't display the value correctly, but instead show 18446744073709549600):
    EXT-exponent: 0x100000000111110b
    EXT-fraction: 0x1111111111111111111111111111111111111111111111111111000000000000b
    --> Decimal: 18446744073709549568
    The above EXT value converts exactly to U64 using the To Unsigned Quad Integer "bullet". But then let's try to flip the blue bit from 0 to 1 in the fraction part of the EXT, making this value:
    EXT-exponent: 0x100000000111110b
    EXT-fraction: 0x1111111111111111111111111111111111111111111111111111100000000000b
    --> Decimal: 18446744073709550592
    The above EXT value is still within U64 range, but the To Unsigned Quad Integer "bullet" converts it to U64_max which is 18446744073709551615. Unless I've missed something this must be a genuine conversion error from EXT to U64?
    /Steen
    CLA, CTA, CLED & LabVIEW Champion

  • Converting binary to floating point?

    ok, i am programming a little java program at the consulter
    the main idea of the program is to convert a decimal number to IEEE (floating point)
    i am almost done except the exponent part
    i dont understand the logic behind it
    so, for example:
    -6.625 = 110.101 (binary)
    after normalization it will be -1.10101 * 2^2
    so the IEEE will be
    1 10000001 10101000000000000000000
    i understand the sign part and the fraction part
    but i have no idea how the exponent part came like this
    the book say that 129-127=+2 so the exponent is 10000001
    da, where it came from ???
    i will appreciate it if someone explain this part for me step by step
    thank you,
    Edited by: abdoh2010 on Jan 26, 2008 2:37 AM

    got it
    thank you for viewing my question

  • How to restrict the decimal place of a floating point number?

    Hi,
    Here is my code:
    public void TwoDecimal(double u){
         String w = Double.toString(u);
         int c = w.length();
         System.out.println(c);
         if (c <= 5)
            double a = Double.parseDouble(w);
            System.out.println(a);
         else
            System.out.println("Invalid input!");
      }I want to show a floating point number which has 2 digits and 2 decimal places, e.g. 45.82, 29.67. This number is input by user and passed as a parameter.
    For those case like the above sample floating point numbers, it can display the proper value of 'c'. e.g. 45.67 will display 5.
    However, when I passed 99999, it will show 7; 9999 will return 6, not 5.
    So, if the user does not input the '.', does it append 2 implicit chars to it? i.e. 99999.0 and 9999.0. So, that's why it returned 7 and 6 for the length of the string respectively.
    How can I fix it?
    and
    Does it has better algorithm?
    Pls advise.
    gogo

    When dealing with a known precision, in your case hundredths, it is often a good idea to use an integer type and add in the decimals on printing only. This is often the case in banking systems. Almost all of them use integer types, (read long) in pennies to store monitary values. Ever seen someone type in a value for a credit card machine? For something like $20 they press.. "2" "0" "0" "0" The machine knows the lowest denomonation in a cent, so it knows where to put the decimal place. I suggest you do something like this. It also helps to avoid base 2 round off errors.
    -Spinoza

Maybe you are looking for

  • Java vs. C# for a new project

    Hi, I know this has probably been done to death, but the world changes and the old arguments lose their validity so I'd be interested in people's thoughts: I work for a largely C# shop, but due to a general dislike of .net and Microsoft from the deve

  • Jpanel woes...

    Hi! Im trying to make a way to highlight a button on my application... What I would like to do, is to have a jpanel behind the button, extending beyond the edges of the button just a bit, and have the color of the jpanel vary a bit. So it would wind

  • MSTSCLib ActiveX RemoteApp Launched Application/Child forms open in middle of multiple screens

    Im using axMsRDPClient7NotSafeForScripting and connecting to windows 2008 r2 server in RemoteApp or "RemoteProgram.RemoteProgramMode = true". Everything opens fine, but the applications are opening in the center of screen which is fine until there is

  • Inserting into Table-in-Table after re-execution the Outer Table query

    Hi Gurus, I have a problem with inserting into Table-in-Table after re-execution the Outer Table query: The problem: I have two tables; both tables are based on VO; tables have a VL between them; The Inner Table is hidden when page lode. I'm executin

  • Importance of Doc. date in a PO

    Hi, I migrated all Open (full and partial) POs from a legacy SAP system to a new SAP. Before uploading POs to the new system, I changed the Doc Date of the uploaded POs. Will this action effect the vendor payment due dates and planned goods received