Forum Discussion

weikang_Hu_9799's avatar
weikang_Hu_9799
Icon for Nimbostratus rankNimbostratus
Nov 27, 2007

Got a negative integer which returned by getLow();

As the structure defined as below . high/low are unsigned integer .

 

struct Common.ULong64 {

 

 

long high;

 

 

long low;

 

 

};

 

However, I got a negative integer ..

 

low= -752457817

 

high= 1

 

result = -752457817

 

 

my code as below and can someone help me to solve it ?

 

public long getVSInfo(String[] vs_list) throws Exception

 

{

 

String[] Server_Names = m_binding.get_list();

 

iControl.LocalLBVirtualServerVirtualServerStatistics Statistics_list = m_binding.get_statistics(vs_list);

 

iControl.LocalLBVirtualServerVirtualServerStatisticEntry[] StatEntry = Statistics_list.getStatistics();

 

iControl.CommonStatistic[] commonstat=null;

 

for (int j=0;j{

 

commonstat= StatEntry[j].getStatistics();

 

}

 

long myresult = (commonstat[5].getValue().getHigh()<<32)|commonstat[5].getValue().getLow();

 

System.out.println(" low= " + (commonstat[5].getValue().getLow()));

 

System.out.println(" high= " + (commonstat[5].getValue().getHigh()));

 

System.out.println(" result = " + myresult);

 

System.out.println("______________________");

 

//return commonstat[5].getValue().getLow();

 

return myresult;

 

}

 

 

 

4 Replies

  • Actually, the values are signed, not unsigned. The problem is that when I wrote the original iControl interfaces, java didn't support the XML Schema "unsigned long" type. Maybe that's changed now, but we can't change the interface without breaking backward compatibility. The structure was titled ULong64 but we had to make a type change at last minute and all the interfaces didn't make the change to the Long64 structure.

     

     

    Since you work in java more than I do (I do very very little), does java support unsigned types now? Also, does it support 64 bit numbers?

     

     

    If so, the likely problem with your conversion code:

     

     

     long myresult = (commonstat[5].getValue().getHigh()<<32)|commonstat[5].getValue().getLow();

     

     

    is that the LSFT 32 of the high value is likely casted into a 32 bit value, not the top 32 bits of a 64 bit value. This will result in a 32bit value of zero and when you OR that with the low value, you'll get a low value.

     

     

    I believe Don had a conversion process for java to build native 64 bit values from the Common::ULong64 structure but I can't seem to find it. I'll dig around...

     

     

    -Joe
  • Don_MacVittie_1's avatar
    Don_MacVittie_1
    Historic F5 Account
    Joe's code will work fine.... Java now implements longs as 64 bit numbers, and supports unsigned longs, so all should be great if you use his code. My only suggestion would be to declare myresult in his sample as unsigned long instead of long, so you don't get rollover on very large numbers.

     

     

    Oh, and the UsefulU64 class in the wrappers will just handle all of this for you, if you have the wrappers downloaded. Unfortunately, we can't offer the source at this time, but it will do the conversions for you.

     

     

    Don.
  • I do not know how the Java support unsigned long , but I changed my code as below and it seems to be work now.

     

     

    long myresult_low = (long)(commonstat[5].getValue().getLow());

     

    long myresult_high= (long)(commonstat[5].getValue().getHigh());

     

    long myresult = (long)(commonstat[5].getValue().getHigh()<<32)+(long)(myresult_low);
  • Don_MacVittie_1's avatar
    Don_MacVittie_1
    Historic F5 Account
    Hey Weikang,

     

     

    That will work just fine except for very large values - which our statistics do generate sometimes.

     

     

    Try this:

     

     

    unsigned long myresult_low = (unsigned long)(commonstat[5].getValue().getLow());

     

    unsigned long myresult_high = (unsigned long)(commonstat[5].getValue().getHigh());

     

    unsigned long myresult = (unsigned long)(myresult_high <<32) + (unsigned long)myresult_low;

     

     

    That will work for any value we can represent, and you won't have to worry about numbers approaching 2 billion.

     

     

    Don.