Convert unsigned integer to IEEE float

Hello,
Is there a typecast function in CVI that would convert 2 unsigned integers to IEEE loat?
eg:
1st value MSB:  50588
2nd value LSB: 16425
Actual reading:  -5000.02
Thanks.
TN
Solved!
Go to Solution.

You just need to do some pointer manipulation to build your float.
But you need to be aware of the size of the data types you're using.  Based on your example values, it looks like you are using the IEEE single precision format, which is 4 bytes.  In 32 bit operating systems, the unsigned int is also 4 bytes.  So you can't combine two unsigned int into an IEEE single without casting them as short ints, which are 2 bytes each.  You would need to check if the value in your unsigned int will fit in an unsigned short before casting it.
You can play with the sizeof() function to see the data type sizes on whatever platform you're using.
Here are a few lines of code the combine your example values to produce the expected result.
#include <ansi_c.h>
#include <utility.h>
main()
 // allocate room for myFloat (IEEE single precision)
 float myFloat;
 // create pointers to the two words in the IEEE single precision format
 unsigned short *pMSW, *pLSW;
 // move the pointers to the first and second word in your float
 pLSW = (unsigned short *) &myFloat;
 pMSW = pLSW +1;
 // initialize the word values
 *pMSW = 50588;
 *pLSW = 16425;
 // print everything out
 printf("MSW: %d\tLSW: %d\tIEEE Single: %f\n", *pMSW, *pLSW, myFloat);
 // wait for a response
 printf("Press any key to continue...\n");
 GetKey();
Here's a link to a discussion on going the other way, which has a sample program and links to more IEEE format info.
http://forums.ni.com/t5/LabWindows-CVI/How-to-convert-a-number-to-32-bit-binary-or-Hex/m-p/977159#M4...

Similar Messages

  • Convert 8 bit unsigned integer to binary (base 2)

    i am trying to convert an 8 bit unsigned integer to binary (base 2) representation and use 8 LED's to show this representation.
    Like for integer 10, the binary is 00001010.....so the LED' s 1 and 3 should be on...

    The LED (boolean) indicators are simply placed into an array.
    To "borrow" an example of such a display, you could have a look at the code written for the parallel port example that can be found under the Help menu:
    Help > Find Examples :  Search "parallel"  HAve a look at the 1st or 2nd example.  They have LED's wired to a U8 array  (I think..  It's been a while since I looked at the example...   )

  • Convert Hexadecimal to IEEE float

    HI
    I am trying to convert a HEXADECIMAL CAN message (inputted via Valuecan USB connector)into IEEE Float format.
    In the VI I can read the Hex message example: 40 89 58 1E. This equates to ~4.29 volts
    If I read this using the NI CAN card the set up is:
    Byte Order: Motorola
    Data Type: IEEE Float
    Start bite: 24
    End Bits: 32.
    Any ideas.
    Best regards
    Allan Johnstone

    Hello Allan,
    just use the type cast function. Have a look at the attached example.
    The string control is set to hex-view, the type is set to SGL as you supply 4-byte representation. (A DBL would need 8 bytes.)
    Best regards,
    GerdW
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome
    Attachments:
    TypeCast_SGL.vi ‏11 KB

  • Php Pack/unpack unsigned integer equivalent

    I'm trying to port some PHP code into Java which contains calls to Pack and Unpack which I'm trying to use which I'm having some problems with converting.
    I realise Java doesn't have these functions but I've been fiddling around and looking around the net trying to get a solution. The php is using 'I' as its format mask which is Unsigned Integer so I've used :
    Integer.toBinaryString(toStringInt)
    which should be returning the unsigned integer but I'm having trouble trying to get it back from the binary string.
    When I stick the result of the above code into Integer.parseInt(string, int) it gives me a number format exception
    Can anyone help?
    Thanks

    ok but how do I set the lower 32 bits? And what is setting the highest bit even doing because I have no idea how the server will respond if I don't set it. As I said I'm porting this from PHP which does all of this and doesn't explain why so I don't know what it's doing it for. The PHP is
    function _encodeHeader($isFromServer, $isResonse, $sequence)
         $header = $sequence & 0x3fffffff;
         if($isFromServer)
         $header += 0x80000000;
         if($isResponse)
              $header += 0x40000000;
         return pack('I', $header);
    That is what I'm porting from so that is why I'm setting the highest bit.

  • Modbus real to unsigned integer conversion

    Is there any alternative way of decoding the two unsigned integer 16 bit words received through Modbus when using reals? I am using the join numbers and type cast functions; however I am not able to download the complete Modbus list to a compact RIO with 32 MB RAM as it runs out of memory.

    Khalid,
    Thanks for your response. However, let me tell you more about my problem:
    Basically my project consists of:
    1. A list of shared variables within a library that also contains modbus slave with the communication settings.
    2. (5) VIs that used to convert UInt16 to Single (for inputs) and Single to UInt16 (for otputs)
    3. (1) VI to display information
    As I try to download into a cRIO-9002 with 32MB of RAM, the device drops the communication and goes into safe mode, blinking the STATUS light 4 times, this means "run out of memory" .
    I would like to know if there is any other alternative way to overcome this problem. Join and cast is functionally correct but it uses too much RAM

  • IEEE Floating point format converstion to ForteDouble

    Question:
    Given that I have 4 bytes of binary data which represents a number in
    IEEE floating point format,
    and I wish to convert it to a Forte DoubleData, will the following code
    give me the correct answer
    in Value?
    (Assume that file is correctly set up, etc...)
    Value : DoubleData = new;
    FPoint : point to float;
    F : float;
    LineText : BinaryData = new;
    File.ReadBinary(LineText,4);
    Fpoint = (pointer to Float)(LineText.Value);
    F = *Fpoint;
    Value.SetValue(F);
    Thanks
    To unsubscribe, email '[email protected]' with
    'unsubscribe forte-users' as the body of the message.
    Searchable thread archive <URL:http://pinehurst.sageit.com/listarchive/>

    Mark,
    you might try testing whether forte floats are IEEE in the following
    way using the following:
    pflt : pointer to float = (pointer to float) (res.value);
    flt = *pFlt;
    however, I believe you will have to wrapper a C function to do this.
    The C function takes a void * first argument and has a float
    void ConvIEEE(void * buffer, float * return)
    return = (float) (buffer);
    or
    void ConvIEEE(void buffer, float return)
    ieeefloat ie;
    ie = (ieeefloat) (*buffer);
    *return = IEEELibraryConvertToFloat(ie);
    depending upon whether C floats are IEEE or not on your
    platform/compiler. I think you'll have to investigate this yourself,
    or try the first approach and see if it works.
    Good luck!
    assuming, of course, that your C compiler's float is also IEEE format.
    Your forte wrapper would look like
    class floatWrapper inherits from framework.object
    has public method ConvIEEE(input buffer : pointer,
    output return : float)
    end class;
    with your binarydata you would
    res : binarydata = (get from somewhere)
    flt : float;
    fw : FloatWrapper = new;
    fw.ConvIEEE(res.value,flt);
    Mark Sundsten wrote:
    >
    Question:
    Given that I have 4 bytes of binary data which represents a number in
    IEEE floating point format,
    and I wish to convert it to a Forte DoubleData, will the following code
    give me the correct answer
    in Value?
    (Assume that file is correctly set up, etc...)
    Value : DoubleData = new;
    FPoint : point to float;
    F : float;
    LineText : BinaryData = new;
    File.ReadBinary(LineText,4);
    Fpoint = (pointer to Float)(LineText.Value);
    F = *Fpoint;
    Value.SetValue(F);
    Thanks
    To unsubscribe, email '[email protected]' with
    'unsubscribe forte-users' as the body of the message.
    Searchable thread archive <URL:http://pinehurst.sageit.com/listarchive/>--
    John Jamison [email protected]
    Vice President and Chief Technology Officer
    Sage IT Partners, Inc.
    Voice: 415 392-7243 x 306
    Fax: 415 391-3899
    Internet Enabled Business Change
    http://www.sageit.com
    -----------------------------------------------------

  • Unsigned integer problem

    Hi,
    I have a problem of converting a CRand32 function from C to Java which was originally from IDA decompiler.
    There's one thing that's troubling me for quite a long time which is the lack of unsigned types, I could not do operations such as byte shifting correctly and the end result I get is sometimes a negative number or larger than 4billion.
    This CRand function should only generate 0 ~ 4billion.
    Can anyone enlighten me in this? As it's the first time I am doing such things.
    Here's the code I have from direct translation from C to Java :
        private transient long seed1, seed2, seed3; // In the code this is an unsigned int_32
        public final long CRand32__Random() {
         // assume the seed is already an unsigned long..
         seed1 = ((seed1 & 0xFFFFFFFE) << 12) ^
              (((seed1 << 13) ^ seed1) >> 19);
         seed2 = ((seed2 & 0xFFFFFFF8) << 4) ^
              (((seed2 << 2) ^ seed2) >> 25);
         seed3 = ((seed3 & 0xFFFFFFF0) << 17) ^
              (((seed3 << 3) ^ seed3) >> 11);
         return (seed1 ^ seed2 ^ seed3);
        }Thanks,
    Edited by: LightPepsi on May 30, 2010 11:40 PM
    Edited by: LightPepsi on May 30, 2010 11:40 PM

    LightPepsi wrote:
    That was the first thing which comes to my mind by changing >> to >>>, however the numbers generated are usually not within the range of an unsigned integer.
    It can be sometimes a negative number or larger than 4 billion and thus making the randomizer inaccurate.One possibility is to use ints for the internal shifts, but create a long as
    long unsignedValue = intValue & 0xFFFFFFFFL;for returning the number and possibly for any internal comparisons you need to make.
    Winston

  • Converting unsigned to java signed byte value

    Hey ,
    i need to use a raw address in a client i am writing but, of course, the address contains a byte outside of the java signed byte range. if any one could tell me what an unsigned byte of 224 in signed java is i would be very grateful, if you could also show how you did this it would be appreciated. thank you =)

    Re: Converting unsigned to java signed byte value
    i need to use a raw address in a client i am writing
    but, of course, the address contains a byte outside
    of the java signed byte range.
    if any one could tell
    me what an unsigned byte of 224 is in signed java
    I would be very grateful, if you could also show how
    you did this it would be appreciated. thank you =)You misunderstand signed/unsigned.
    A byte has 8 bits. It can represent 256 different values.
    Viewed as an unsigned scalar the range is [0;255].
    Viewed as a signed two's-complement scalar the range is [-128;127].
    Values [0;127] are obviously the same byte values in the two views.
    What the other half of the possible byte values represent depends on what view you adopt.
    You don't need to convert anything.
    public final class Byte224 {
        static byte[] byteArray = {
            (byte)224, (byte)'\n'
        public static final void main(final String[] arg) {
            System.out.println("0x"+Integer.toHexString(byteArray[0]&0xff));
            System.out.println(Integer.toString(byteArray[0]&0xff));
    }

  • Convert an Integer variable to a tring

    Hi everyone,
    This Shake script below is part of a much bigger one that loads multiple SfileIns. I need to convert the integer data into a string to make it work. How can I do that ? Thanks in advance for your help.
    string path = "/data/job/sequence";
    string path2 = "[email protected]";
    int num = 1;
    string final = pathnumpath2;
    SFileIn(final,
    "Auto", 0, 0, "v1.1", "3", "");

    I think you might want to try the -curve option, which is defined on page 1023 of the manual.
    There is an example of its use with string substitution on page 1029.
    (Note how the printf-type function syntax--e.g. %d--is used to convert integers into strings.
    Hope that helps!

  • Convert an integer value that was created with the Excel DATEVALUE formula to a valid date?

    Hello everyone,
    How can I convert an integer value that was created with the Excel DATEVALUE formula to a valid date in SSIS?
    Is this even possible?
    For example:
    =DATEVALUE("8/22/2008") will format the cell to display 39682.
    Reading the column as a string to get the int value (39682) - how can I turn this into a valid date using SSIS and then importing the real date to sql server?
    Thank you!

    You can use Script component for this and convert your integer values to Date. An example here is following:
    CultureInfo provider = CultureInfo.InvariantCulture;
    string dateString = "08082010";
    string format = "MMddyyyy";
    DateTime result = DateTime.ParseExact(dateString, format, provider);
    Source: http://stackoverflow.com/questions/2441405/converting-8-digit-number-to-datetime-type
    Vikash Kumar Singh || www.singhvikash.in

  • How to convert an Integer to int

    Integer y = new Integer(1);
    int x = ????(y);
    What is the missing command to do the above conversion ?
    I've tried casting etc.
    It's mid nite and I'm still at work!
    Appreciate all help. Thanks!

    Integer is an Object. int is a primitive base type. to convert an Integer Object into an int:
    //let's say you read a line from a file, and the line is this
    5
    //normally, since files contain characters, you would call a method that reads in String Objects
    //so the 5 is actually a String, which you need to convert to an int to use for math, calculations,
    //expressions, etc.
    String blah = Keyboard.readLine();
    int x = Integer.parseInt(blah);
    // now x equals the int 5.
    hope this helps.

  • How to convert form Integer to Object

    How do I a convert from Integer to Object?

    ZIP codes are not integers because one does no
    arithmetic with them.Sure they do. Look at this zip code:
    90210-0001
    Looks like subtract 1 from 90210 to me. <joking/>Well US zip codes yes but Canadian zip codes are
    alpha numericbase 36 you mean.

  • How to convert nagative integer to positive integer.

    int i= (int)System.currentTimeMillis();
    System.out.println(i);
    The result is nagative
    such as;
    -585450145
    How to convert nagative integer to positive integer.

    Isn't it enough to multiply the integer with -1?!?
    Or did � understand something wrong?
    slaps head
    Yes, but an int is only 32 bits wide; a long is 64
    bits wide.
    The fact that the int is negative isn't "real" - it's
    because they cast it to the wrong type. System time
    in millis is returned as a long, and that's what it
    should be cast to.
    %Doh, I'll get me coat.

  • How to scale 32-bit signed integer data to floating-p​oint voltage when acquring data in DAQmx by PXI4472?

    I acquired data in DAQmx by PXI4472. For the high speed data logger, I used "DAQmx Read" to read unscaled 32-bit signed integer data.
    Now, my question is how to scale 32-bit signed integer data to floating-point voltage?
    I think that it's (20/(2**24))*I32 because the voltage range of PXI4472 is -10 to +10 and its resolution is 24 bits. But I cann't get correct voltage by that formula.

    While you could hard code the scaling factor, it will be more flexible if you retrieve the scaling coefficients from the driver. To do this, you need to use the Analog Input>>General Properties>>Advanced>>Device Scaling Coefficients>>Device Scaling Coefficients properties under the DAQmx Channel Property Node. Look at the documentation for this property to see how it can be used to create a polynomial equation for scaling to volts.
    Since you are creating a data logging solution, you may want to consider using a compressed data stream from the driver instead of the I32 data type. This will allow you to read the data back as a stream of u8's instead. Since the PXI-4472 is 24 bits, you will only have to write 3 bytes to disk for each sample instead of 4. You can check out the following examples for how to create an application using this compressed data stream. It also shows how to use the scaling coefficients to transform the unscaled data back to voltage values.

  • Convertion to integer from array and logical mask

    hi all.
    please look at my VI.
    1)i want to convert this array to 4 display. each displaywill show one element(=1 row, in this case) from the array. 
        how i do it ?
    2) i need to make logical mask  to those numbers. how i convert the integer number to binary and make this logical mask ?
    with best regards
    pro111
    Message Edited by pro111 on 12-02-2006 05:41 PM
    Attachments:
    Untitled 2.vi ‏6 KB

    Hi pro,
    I did not follow you and came up with another example while Christian was doing his.
    This is my guess at what I thought you were asking.
    Ben
    PS Christian, I am not trying to side step your example. I figured if I drew it up I should post.
    PPS talk about a post collision!
    Message Edited by Ben on 12-03-2006 12:32 PM
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction
    Attachments:
    ConvetI32.JPG ‏76 KB

Maybe you are looking for

  • Font selection view control in Web Gallery

    LR4.1 RC2 I wanted to be able to change the font type from the UI panel using a font select popup. This control really only seems to exist in the inbuilt edit modes (eg: id plate and watermark) so I have tried a workround which seems to work OK so fa

  • Problem overring equals, hashcode on a LinkedHashMap

    Hello, I have a "LinkedHashMap<MyObject, Integer> mymap; now I filled it and I want to keep the order of insertion; {code} class MyObject { public Map<String,Integer> names = new LinkedHashMap<String, Integer>(); {code} after that I created a new MyO

  • Exporting CP 5 to PDF - how much functionality should I expect?

    Hello, I've been reading the Captivate forum for hours and I've learned so much, thank you to all the awesome contributors. However, either I'm missing something or I'm trying to do something stupid that has a better solution. Anyway, I need to expor

  • SolidWorks 07 configs

    Hi When i import an assembly into Adobe 3D 8 from Solidworks 2007 the option of what config to use appears, e.g i choose the cross section config, certain parts of the assembly will cross section, but most of it won't and sometimes the part won't eve

  • Urgent: OAM authorization

    Hi all, I am trying to implement authorization such that the user belonging to a certain group in oid (oid is my user store) are allowed to see a page .I have Implemented the Authorization policy accordingly but somehow it is not coming into effect a