Unsigned integer

Hello,
I am trying to wrap a c++ dll ,where most of the variables are (unit8,unit16,uni32 ) unsigned integers.
Since java doesnt have usigned integer type,I am wondering what to do.
1. Pass the usigned int value as a string to the c++ program.Convert from string to uint in the C++ code.
would be one option.
I am hoping that there are other options available to do this more gracefully.
thank you very much,
Regards

I agree that signed and unsigned numbers differ in interpretation of the bits so one can disregard this when passing the data to/from DLL.
When you get an uint32 from the DLL it can be stored in a Java int type:
int i=fromDLL();but it should be converted to long when used:
long ui=(long)i&0xffffffff;to pass "unsigned" to the DLL convert it to int:
toDll((int)ui);You may also need to perform little/big-endian conversion.
Dmitry Hudyakov
Brainbench MVP

Similar Messages

  • 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.

  • How to return array of unsigned integer pointer from call library function node & store the data in array in labview

    I want to return array of unsigned integer from call library node.
    If anybody knows please help me
    Thanks & Regards,
    Harish. G.

    Did you take a look at the example that ships with LabVIEW that shows how to do all sorts of data passing to DLLs. I believe your situation is one of the examples listed. You can find the example VI in the "<LabVIEW install directory>\examples\dll\data passing" directory.

  • 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...   )

  • 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

  • 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

  • Iteration a signed integer and not an unsigned integer, why?

    i was just wondering if there is a reason for keeping the iteration variable/indicator of a loop a signed 32 bit integer.
    it is never going to take a negative value.. then why signed; unsigned could have served the purpose
    Message Edited by Ujjval Shah on 07-08-2009 09:21 AM
    Solved!
    Go to Solution.

    Remember that array sizes are limited to I32 (the "size" input to initialize array is I32, the output of Array size is I32, etc), so running a FOR loop more than 2^21 times is not even possible (N is also I32).
    While loops can of course run forever, so if you need to increment a counter more than 2^31 times, you can use a shift register with U64, for example. However, don't even try to autoindex an output tunnel of such a loop, you're almost guaranteed to run out of memory before you reach the limits of I32.
    Using array indices as I32 has several advantages. For example sometimes you need an invalid index (Integers don't have NaN!), so having a negative number is very useful. For example if you use "search array" and no match is found, the output is -1.
    I suspect in the very long run these things will change. In another decade, all OSs will be 64bit or more and RAM will be mesured in TB. LabVIEW will need to evolve too to keep up. 
    LabVIEW Champion . Do more with less code and in less time .

  • Writing double and unsigned integer to serial port

    Hi all
         I have a basic question.  I am trying to write a double or unsigned intger to serial port.  Is it possible to do so?  If it is he case, how do I do it?
    Thank you very much.
    Best
    Hideya

    Hideya,
    The serial port sends one text character at a time. So you must convert your numeric value to a text or string representation and then send the string.
    LabVIEW has several functions on the String palette for numeric conversions. You must decide how to represent the number as text, floating point or exponential notation, number of significant digits, and other formatting issues. These may be dependent on what will be done with the data after being sent.
    Lynn

  • 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...

  • Unsigned int to integer conversion

    Hi,
    I have an unsigned integer column in my database table. If I try to retreive the value of the column using resultset.getInt() I'm getting "Numeric value overflow" error as it exceeds the INT_MAX value.
    For eg., if the column value : 4294967295, the expected value from resultset.getInt() is -1 or Numeric Value Overflow error ?
    Is it valid to retrieve the value using getInt() or should I use getLong()?.
    Kindly Clarify.
    Thanks,
    Radhika.

    use getLong

  • ACS v5.2 - Unable to update User integer attributes through File Operations

    Hi,
         I have created some internal users on ACS v5.2 and added some Unsigned Integer attributes for each user. I am trying to do a bulk update of these integer attributes using the File Operation facility. However no matter what number I put on the import template it doesn't get updated and displays a "0" in the user config.
    The import template is validated successfully with no errors and also the string attributes are updated correctly.
    There is a sort of work around of deleting the users and adding them back in with the updated values. But this is not feasible as it would reset their passwords. I have also tried saving the csv file in Open Ofifce instead of Excel
    Has any one else come across this problem?
    (I am unable to see this issue in the Release notes or Bug tool kit although there is a similar issue when updating devices in CSCth68051)

    Hi,
         Thanks for the reply. I have managed to recreate the problem to show you but it is a bit more complicated than I first thought. The problem only occurs when the integer attributes are added after the user is created.
    I created a dummy user. The MTL and TLS attributes were present before the user was added. I then added the XXX and ZZZ attributes afterwards and assigned them default values. The default values show up in the GUI config.
    However when I export the database to a csv file only the values of the MTL and TLS attributes show up in the export file:
    I then downloaded an import template and updated the integer values for TLS,MTL, XXX and ZZZ for the dummy user:
    The file imports successfully with no errors. However, when I display the user config only the MTL and TLS attributes have changed. The XXX and ZZZ attributes have stayed the same.
    I thought it might be because I was assigning a default value of 0 to the new attributes but I assigned ZZZ a default value of 1 and the same thing occurred.

  • No warning when assigning to an unsigned char from unsigned int

    Is this an error in VC++, or am I missing something?  The following code should give two warnings for assigning to a smaller type, but only gives one: (compiled as 32 bit)
    unsigned
    char c;
    unsigned
    int i = 24;
    // 32 bit unsigned integer
    unsigned
    long L = 25;
    // Also a 32 bit unsigned integer
    c = L; // Warning C4244
    c = i; // no warning
    This happens in Visual Studios 2005, 2010, 2012, 2013 and 2015, at least.

    Is this an error in VC++, or am I missing something?  The following code should give two warnings for assigning to a smaller type, but only gives one: (compiled as 32 bit)
    unsigned
    char c;
    unsigned
    int i = 24;
    // 32 bit unsigned integer
    c = i; // no warning
    This happens in Visual Studios 2005, 2010, 2012, 2013 and 2015, at least.
    Have you tried it with Warning Level 4?
    In VC++ 2008 Express and W4 I get:
    Warning 2 warning C4244: '=' : conversion from 'unsigned int' to 'unsigned char', possible loss of data
    - Wayne

  • How to specify in TS unsigned long? unsigned short?

    Hi,
    I'm lusing a c/c++ step type from TestStand.
    I need to use a structure whose fields according to the h file of the dll are:
    unsigned char
    unsigned long
    unsigned short
    Now, when I define a container in TestStand (to interface with the dll structure) my options are:
    integer
    unsigned integer
    etc...
    What am I supposed to do ?  what is the appropriate numeric format? 
    Thanks

    Hi Doug,
    I'm given the dll and load of h files.  The definitions you mentioned are not shown...
    Suppose I want to creat in TS a container to match variable FCPortConfig.  This variable structure is given here....
    typedef struct tagFCPortConfig
     unsigned char  ucTopology;    /* For Point-To-Point use TOPOLOGY_PT_2_PT
                  and for LOOP Topology use TOPOLOGY_LOOP */
     unsigned char  ucSpeed;     /* SPEED_1GHZ, SPEED_2GHZ       */
     unsigned char  ucDisableTimer;  /* (Not Currently Used) enable or disable
                  timeout timer          */
     unsigned long  ulRRDYGap;    /* (Not Currently Used) up to a 27-bit val */
     unsigned long  ulRRDYGapRandomEnable;/* (Not Currently Used)enable/disable   */
     unsigned long  ulRRDYGapSeed;   /* (Not Currently Used) If random set;
                  a 27-bit val          */
     unsigned long  ulRRDYGapMin;   /* (Not Currently Used) If random set;
                  a 27-bit val          */
     unsigned long  ulRRDYGapMax;   /* (Not Currently Used) If random set;
                  a 27-bit val          */
     unsigned char  ucAutoNegotiate;  /* (Not Currently Used) enable or disable
                  auto negotiation         */
     unsigned short uiBBCreditConfigRx; /* BB_credit this port will advertise   */
     unsigned char  ucStatsMode;   /* Determines weather or not to retrieve
                                              the extended stats counters, use
                                              STATS_MODE_NORMAL & STATS_MODE_EXTENDED */
     unsigned char  ucReserved[15];  /* Reserved */
    } FCPortConfig;
    1) Is there a way to find out how they define unsigned char, unsigned short and unsigned long?
    2) Can I still use the TS default numeric type?
    Thanks
    Rafi

  • Integer and fractional part of the number

    Hello everybody,
    I want to divide the floating point number to 2 integer words, first will receive the interger part of number, and the second will receive the fractional part of the number.
    For example: I have number 751.98 in DBL, then I create two integer fields: first has value 751, second has value 98.
    I have tried simple conversion from DBL to I16, but it always rounded me to higher interger. I don't want to round it. And I just don't know how to transform the fractional part to integer. Are there any specialized functions for this? Maybe should I use log10 or similar?
    TIA,
    Jacek.

    The place to start with this problem is the IEEE-754 numerical
    representations:
    32 bit floating point is internally:
    highest order bit is the sign bit.
    the next 8 bits are the exponent bits
    the last 23 bits are the mantissa bits
    the mantissas and exponents are binary.
    the mantissa value in a 1.22 fixed point binary number, i.e. the most
    significant binary bit is equal to 1, the next most is equal to 1/2,
    the next most is equal to 1/4, etc., etc.
    The exponent part can go between 2^-127 and 2^128
    You should be able to cast your 32 bit float to a 32 bit unsigned
    integer, separate it into sign, mantissa and exponent parts, use the
    exponent to rotate left or right your mantissa decimal point by the
    exponent value and then separate the whole part from the fractional
    part and then put each into the I16's or U16's as you want.
    Douglas De Clue
    LabVIEW programmer
    [email protected]
    [email protected] (Michael Ross) wrote in message news:...
    > This problem needs some limits. Like: only return the decimal portion
    > out to 6 places.
    >
    > First run the number through Remainder and Quotient (divisor of 1).
    >
    > 751.98743674645641000000 gets remainder of
    >
    > 0.98743674645641021900
    >
    > "floor" is 751
    >
    > Take the remainder and send through Decimal to Fractional String (this
    > is where you set your number of decimal places [default is 6]).
    >
    > returns 0.987437
    >
    > Then use String Subset and set it to an offset of 2 (cleans off the
    > leading zero and decimal point) with the "length" input left at the
    > default of "rest" (of string).
    >
    > 987437 (in string form)
    >
    > Now use String to Decimal Number
    >
    > returns 987437 (as a decimal number)
    > ====================================
    > I think if you don't limit the number of places it is ugly. It is
    > ugly going from numbers to strings and then back. But all numbers is a
    > bad thing.
    >
    > The alogirithm for finding the answer mathematically is nasty.
    > Especially without a limit on decimal places. You have to figure out
    > the number of decimal places and multiply by the inverse of the last
    > decimal place. Sounds easy.
    > =============================
    > Try this: New number: 751.98652
    >
    > Truncate out the remainder (Remainder and Quotient (divisor of 1)):
    >
    > 751.98652 ---> 0.98652
    >
    > Mult by 10 ----> 9.8652
    >
    > Take the floor (9) and divide by 10 ----> 0.9
    >
    > subtract the new number from the old. Is the answer non-zero? Not,
    > then keep on
    >
    > 0.98652 - 0.9 = .08652 which not equal to 0
    >
    > If it is zero, the floor is the answer.
    >
    > Continue - Not:
    >
    > This time multiply by 100 ----> 98.652
    >
    > floor is 98, divide by 100 ----> 0.98
    >
    > Subtract 0.98 from 0.98652 = .00652 still non zero.
    >
    > Keep on. 1,000, 10,000...When you get to 100,000
    >
    > 0.98652 x 100,000 = 98652.00
    >
    > Get the floor
    >
    > divide the floor by 100,000 to get the original number (remainder is
    > now 0.000), compare to original remainder
    >
    > 0.98652 - 0.98652 = 0. Yay.
    >
    > Take the 98652 and go with it. The last place was the one hundred
    > thousandth.
    >
    > I can't take credit for the last, I had uglier stuff going on. I did
    > do the string thing.
    >
    > I swear this is just like some sorry homework problem.
    >
    > Mike

  • Represent an 4-byte integer as a hex number???

    Hi everyone,
    I still have problem with converting an IP address to an POSITIVE number. One of the native method expects unsigned integer pass in to set IP address for a device. But, in java, when I convert a big IP such as 192.0.0.0, it will return a negative integer. Many of people helped me out but I still got the problem since my co-worker did not want to change his code. He wanted me to find an alternative way to do. He suggested me to represent the address in hex format will work ok.
    e.g int ipAddr = 0x6C01A7C0; // 192.167.1.108
    Then CallCOMObject(ipAddr);
    So, my question is do we have a way to convert 192.167.1.108 into 0x6C01A7C0?
    Thanks in advance
    Hung.

    Hi Armalcolm,
    Yes, I tried that but the native function throwed exception since the integer I pass in was negative. In the native function, there was an IF statement which would reject all negative integer.
    Here is my example
    After user enter IP as: 192.167.1.108, I convert (by shifting and adding) to an integer and I got an negative integer (-1062796948). Then I passed it in the native function as:
    CallCOMObject(-1062796948);
    The native function throwed exception.
    Is that what you mean, Armalcolm?
    Alternatively, you could do your shifting and adding into a long, and then and the result with >0xffffffff, passing the result. But there should not be any difference. I could shifting and adding into a long, but I don't know how to represent that long number in hex. Can you help me out with that.
    I appreciate for your reply.
    Hung.

Maybe you are looking for

  • Error at Receiver Mail adapter modules

    Hi, We have implemented a receiver mail adapter for producing Excel file as attachment. It is giving the error as follows: Delivery of the message to the application using connection Mail_http://sap.com/xi/XI/System failed, due to: com.sap.aii.af.ra.

  • Webdynpro application deployment problem

    Hi, I am tring to deploy webdynpro application using netweaver studio 2004 version, and using ep6. when I deploy and run application , I get following error:- URL to deploy : file:/C:/DOCUME1/PROCES1/LOCALS~1/Temp/temp32470a.ear Result => deployment

  • Difficulty with Licensing Android apps developed with Flash CS6

    Hi, I'm heading down many a blind alley with this one. I have developed an Android app using Flash CS6 and it is ready to be published on Google Play. However, as it is a paid app, it is strongly advised to license it to protect it. There is a bit of

  • ORA-12514 & Listener Status Instance status Unknown issue

    Dear All, Database Version - 10.2.0.5.0 Operating System - Windows XP I am using Oracle 10g version, which has two services (bit10g and ora10g) installed on it. Service ora10g was working before upgradation of Database to 10.2.0.5.0 and it was fine.

  • Will the EOS utility for the Rebel SL1 work with the 40D?

    We first bought the Rebel EOS 300D many years ago and then upgraded to a 40D at my wifes shagrine (heavier) and have now bought my wife a new Rebel SL1.  I would like to be able to download all three camers on my computer Win7 and her's WinXP.  I'd l