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.

Similar Messages

  • Config.xml file missing after using pack/unpack (WebLogic 12c)

    Hi,
    When I use the utilities pack/unpack to "copy" a domain from one physical server to another one, I end up with the config directory where there is no config.xml file while on the source physical there is of course this file.
    If I use the scp command (I work under Linux) to "copy" the domain I do not encounter problem and I can start the Node Manager and the WebLogic server.
    Did someone faced this situation?
    How did you solved it? Or, is there something that I am missing?
    Kind Regards.

    Hi all!
    I am having the same problem with WebLogic Workshop 8.1 SP4.
    Any idea?
    Thanks in advance.

  • How to pack & unpack in case of selection options

    I have a Ztable having field
    ztable-belnr.
    Now i hav a report which fetch data according to belnr.
    This is a section option:
    select-options: belnr1 for Ztable-belnr.
    Now if i enter 51 it shows no document
    & if i enter '0000000051' it shows the data.
    How to use pack unpack.Plz guide.
    Regards.

    Hi Abhut,
    Check the data element of Ztable-belnr and then to domain to see if it has conversion routine ALPHA or other. If it doesn't have the conversion routine attached to this you need to do this manually in this program.
    You need to use this code before you use this  select options variable.
    loop at belnr1.
    if not belnr1-low is initial.
    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
      EXPORTING
        INPUT         = belnr1-low
    IMPORTING
       OUTPUT        = belnr1-low
    endif.
    if not belnr1-high is initial.
    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
      EXPORTING
        INPUT         = belnr1-high
    IMPORTING
       OUTPUT        = belnr1-high
    endif,
    modify belnr1.
    endloop.
    This fills the zeros automatically.
    Regards,
    Yellappa.

  • 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

  • Difference between pack/unpack and T2P (copyConfig/copyBinary)

    Hi Experts,
    I have a requirement to clone WLS 10.3.3 running SOA and OHS. I am facing some issues (encountering NPE on running copyBinary.sh and extractMovePlan.sh file is missing) while doing T2P for OHS. I see pack.sh and unpack.sh can be used to make WLS domain templates and create new domains on different machines/hosts.
    Please let me know what is the difference between the two approaches T2P and pack.sh/unpack.sh. Also please suggest which is the recommended approach.
    Note: I am new to WLS, so please don't mind if my question is trivial or doesn't make sense.
    Thanks
    Rathnam

    Below is the Stack Trace for NPE:
    =======================================================================================
    Null Point Exception Error:
    bash-3.2$ /than8o/fmw/product/111/oracle_common/bin/copyConfig.sh -javaHome /than8o/fmw/jrmc-4.0.0-1.6.0 -al /ptsadmin/FMW_clone/config/OHS_CopyConfig.jar -sourceInstanceHomeLoc /than8o/fmw/product/111/ohs_instances -sourceComponentName ohs1
    Log File: "/tmp/CLONE2012-09-19_03-56-21PM-LOG/CLONE2012-09-19_03-56-21PM.log".
    Error File: "/tmp/CLONE2012-09-19_03-56-21PM-LOG/CLONE2012-09-19_03-56-21PM.error".
    To proceed, type "yes":yes
    INFO : Sep 19, 2012 3:19:23 PM - CLONE-21095 Create archive for instance1@ohs1 started ...
    java.lang.NullPointerException
    at oracle.as.clone.classloader.CloningFrameworkClassLoader.getClonableEntityTypes(CloningFrameworkClassLoader.java:162)
    at oracle.as.clone.classloader.CloningFrameworkClassLoader.<init>(CloningFrameworkClassLoader.java:254)
    at oracle.as.clone.classloader.CloningFrameworkClassLoader.getInstance(CloningFrameworkClassLoader.java:222)
    at oracle.as.clone.cloner.component.ComponentCreateCloner.doClone(ComponentCreateCloner.java:66)
    at oracle.as.clone.cloner.Cloner.doFinalClone(Cloner.java:56)
    at oracle.as.clone.request.CreateGenericArchive.doGenericArchive(CreateGenericArchive.java:128)
    at oracle.as.clone.request.CreateCloneRequest._clone(CreateCloneRequest.java:69)
    at oracle.as.clone.process.CloningExecutionProcess.execute(CloningExecutionProcess.java:145)
    at oracle.as.clone.process.CloningExecutionProcess.execute(CloningExecutionProcess.java:128)
    at oracle.as.clone.client.CloningClient.executeCloneCommand(CloningClient.java:123)
    at oracle.as.clone.client.CloningClient.main(CloningClient.java:83)
    oracle.as.clone.exception.FMWCloningException: java.lang.NullPointerException
    at oracle.as.clone.classloader.CloningFrameworkClassLoader.getInstance(CloningFrameworkClassLoader.java:227)
    at oracle.as.clone.cloner.component.ComponentCreateCloner.doClone(ComponentCreateCloner.java:66)
    at oracle.as.clone.cloner.Cloner.doFinalClone(Cloner.java:56)
    at oracle.as.clone.request.CreateGenericArchive.doGenericArchive(CreateGenericArchive.java:128)
    at oracle.as.clone.request.CreateCloneRequest._clone(CreateCloneRequest.java:69)
    at oracle.as.clone.process.CloningExecutionProcess.execute(CloningExecutionProcess.java:145)
    at oracle.as.clone.process.CloningExecutionProcess.execute(CloningExecutionProcess.java:128)
    at oracle.as.clone.client.CloningClient.executeCloneCommand(CloningClient.java:123)
    at oracle.as.clone.client.CloningClient.main(CloningClient.java:84)
    Caused by: java.lang.NullPointerException
    =======================================================================================
    Basically I am looking at knowing the difference between pack/unpack and T2P using copyConfig/copyBinary/extractMovePlan.
    Thanks
    Rathnam

  • 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

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

  • Pack / Unpack Material Number

    Dear Sap Expert.
    We have a scenario where the material is part of finish BOM which is unpacked.The same material we want to send it to subcontactor for doing packing.
    The same material is sold as finshed spare part.
    How to map this scenario.The material is having PD as MRP type.
    Waiting for your valuable contribution.
    Yogesh Walde
    MM Consultant
    09881203422

    qwwwe

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

  • Packing and Unpacking BITS from a SHORT

    Hello everyone,
    I am have six pieces of data packed into a 16bit short value and I am wondering if my code to pack and unpack the short looks right to everyone else. The six smaller values that I am pulling out of the short are of the length (in order) 2+2+3+3+3+3 bits . My approach to unpacking the short is applying a bitmask to isolate just the sub-value I want, then using the bitwise-left shift ( << operator) to move that value to the 0-position in the short, then casting the value to a byte for use in my program. The code to do that looks something like this:
    public final short maskValue1 = Short.parseShort("0000000000000011", 2);
    public final short maskValue2 = Short.parseShort("0000000000001100", 2);
    public final short maskValue3 = Short.parseShort("0000000001110000", 2);
    public final short maskValue4 = Short.parseShort("0000001110000000", 2);
    public final short maskValue5 = Short.parseShort("0001110000000000", 2);
    public final short maskValue6 = Short.parseShort("111000000000000", 2);
         public void unpackEncodedMap(short map, byte[] outMap) {
              outMap[0] = (byte)((map & maskValue1) << 14);
              outMap[1] = (byte)((map & maskValue2) << 12);
              outMap[2] = (byte)((map & maskValue3) << 9);
              outMap[3] = (byte)((map & maskValue4) << 6);
              outMap[4] = (byte)((map & maskValue5) << 3);
              outMap[5] = (byte)(map & maskValue6);
    The approach I use to encode the short value involves taking my input byte array and casting each into a short. Then I use the bitwise-right shift operator ( >> ) to move the bit value into the appropriate position. To apply the next byte-value I bitwise-OR the previous value onto the new mask. The values in the byte-array are assured not to be greater then their sub-value bit lengths ... so the downcast is all right. Here is my code to do the packing:
         public short encodeMap(byte[] mymap) {
              short out = (short)(((short)mymap[0]) >> 2);
              out = (short)((out | ((short)mymap[1])) >> 2);
              out = (short)((out | ((short)mymap[2])) >> 3);
              out = (short)((out | ((short)mymap[3])) >> 3);
              out = (short)((out | ((short)mymap[4])) >> 3);
              out = (short)(out | ((short)mymap[5]));
              return out;
    Thanks for looking at my functions and point out any inconsistencies. I feel like there is something I am not seeing in my code. Thanks!

    Well...thanks for the one-line answer :) yes, in the sense that it compiles and runs, but I am not sure if there is a problem with my logic or not.My program is acting strange and I am trying to isolate my problem, I think the problem might be in my pack/unpack methods.... possibly in my bit-math.

  • 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

Maybe you are looking for