Unsigned Long declaration in JAVA ?????

Hi,
Java doesnt allow unsigned declaration.
I have a 'C' program which does the following:
unsigned long someLongInteger; //in C
someLong>>18;
SomeLong<<14;
SomeLong>>=14;
When I did the same thing in JAVA by declaring someLongInteger as long, it gives me a different result.
Is that because it is considering java Long as signed??
Is there any work around this?
I appreciate your reply
Thank you.

Depending on what you are trying to do, the unsigned right shift operator (>>>) may be of use for this situation.
- K
Hi,
Java doesnt allow unsigned declaration.
I have a 'C' program which does the following:
unsigned long someLongInteger; //in C
someLong>>18;
SomeLong<<14;
SomeLong>>=14;
When I did the same thing in JAVA by declaring
someLongInteger as long, it gives me a different
result.
Is that because it is considering java Long as
signed??
Is there any work around this?
I appreciate your reply
Thank you.

Similar Messages

  • Urgent::Unsigned Long Requirement::Oracle Number(38) to Java conversion

    Hi,
    I have a Oracle field configured as NUMBER(38). The number in that field gets incremented sequentially and is currently around 5345232341.
    I am using callableStatement.registerOutParameter(1,java.sql.Types.INTEGER); which is working fine.
    But the problem happens when I am trying to retrieve the value and store it within my Program.
    I am using 'long' to do that but I presume I will hit a problem when the number crosses 9223372036854775807 (2^63-1). As we don't have unsigned long option in Java(unlike in C/C++), how do we achieve this? Please can somebpdy tell me the workaround.
    Currently, I am storing it as follows:
    long my_number = callableStatement.getInt(1);

    Currently, I am storing it as follows:
    long my_number = callableStatement.getInt(1);While reading the docs, you should probably also read about getInt(), because your current code is buggy.

  • Java newbie help (type casting, 64bit unsigned Long)

    Hi I am java newbie and need help on my project. I have a few questions. Can you put strings in a hashtable and test for their being their with the appropriate hashtable method? I want to test for equal strings, not the same object. Second question can you use all 64 bits of an unsigned long? java doesn't seem to allow this. Any packages that do?
    Thanks,
    Dave

    Try casting it to Long instead of long. Long (capital L) is an Object, while long (lower case l) is not. You may also check to make sure the value isn't null. I would have thought that autoboxing would have worked here unless the value was null. But I am no expert on autoboxing.
    Edit >> Checking for null ain't a bad idea but has nothing to do with the problem - this is a compile time problem. Sorry.
    Also>> This code should work:
    long cTime=(Long)session.getAttribute("creationtime");Edited by: stevejluke on Jul 1, 2008 11:00 AM

  • Unsigned Long in java

    Hi all,
    I have a code in C which i want to convert into java.. Iam facing problem because java does not support
    unsigned long.The code in c look like this:
    WCD.cardno = ( SerBuf[3]* 0x00010000UL+
    SerBuf[4]* 0x00000100UL+
    SerBuf[5]* 0x00000001UL);
    I want to convert this code into java. What i have done is something like this
    cardno = (tempBuffer[3]*0x01000000 + tempBuffer[4]*0x00010000 + tempBuffer[5]*0x00000100 +tempBuffer[6]*0x00000001);
    Can anyone help me out. This program is for serial port implementation.
    Thanks
    Kiran

    kiranJNI wrote:
    Basically how can we achieve unsigned long in java???In your case, this isn't going to be a problem for two reasons.
    AFAIK, there aren't any numbers where multiplying them as unsigned numbers is going to be different from multiplying them as signed numbers and still give a valid result. To make this easier, let's work with signed vs unsigned bytes. Negative numbers are those in the range 0x80 to 0xFF; these are the only numbers where the "value" of the byte differs between signed and unsigned. Now think of those numbers as unsigned numbers. The only unsigned numbers you could multiply them by and still remain within the range of a byte are 0 and 1. If you multiply by 2, the result is 0x100, which is larger than what a byte can represent. If the result will remain within the range of the data type, it don't think there are any numbers where signed and unsigned multiplication return a different bit pattern.
    Furthermore, your example doesn't even need multiplication. You're multiplying by powers of 2, so all you really need is a series of shifts and adds.

  • Unsigned data types in Java

    I know this is beating an old dead horse, but I find it frustrating that Java does not support unsigned types. I frequently work with binary file formats that store data in unsigned types. In Java there is no easy way to work with these files. For example, if the file has unsigned longs it is a problem. Also, if the file has unsigned ints, a very common occurrence, I have to "upcast" those numbers into longs. This is expensive from a time and space point of view since data files from satellites can be hundreds of megabytes or gigabytes in size and I have to double them in size just to capture the final bit. It is also inefficient to process these files because now I am using longs (64-bits) on systems that are usually optimized for 32-bits which means processing code takes a big performance hit.
    Also, there is simple confusion. For example, if I provide data from a file to a user and they see "long" where they know they data is an int they start asking questions and I have to start explaining why it is a long instead of an int. Scientists don't like data to be "translated" for integrity reasons so I have make these long explanations how upconverting to a long is not really a translation, etc. It just creates a lot of confusion and problems.
    Also, look at from a developer point of view. The developer has a spec in front of him listing the data types and is now reading the corresponding java class where the data gets loaded--all the data types are different because of the upconverting--it creates confusion.
    Is there any hope of having unsigned types or we all condemned to a lifetime of upconverting?

    JohnChamberlain wrote:
    I thought it was obvious that you need to upconvert unsigned values because otherwise the number will be wrong if the sign bit is set.No. A 32-bit scalar with the high bit set is still correct (bit-for-bit). You only get problems if you perform arithmetic, right-shift or widening-conversion on it, or make a decimal String representation.
    For example, lets say the file has an unsigned int (uint32) value of 0xF1234567 which in decimal is 4,045,620,583. This is a positive number. If you load this value into a Java int value it will be interpreted as the negative number -249,346,713.For a given value of "interpreted"; Integer.toHexString(0xF1234567) produces the expected result.
    Further example: if you load a file containing uint32 values into Java ints and then average all the values you might come out with a negative number. Obviously this is impossible because the file contains only positive numbers so the average of those numbers cannot be negative.Obviously if you need to do this on a number of large 32-bit scalars you need the sum scalar to be 64-bit which means you can mask your way out of any issues when you perform the widening conversion.
       int[] x = { 0xF1234567, 0xF1234565, 0xF1234557 };
       long sum = 0L;
       for(int i=0;i<x.length;++i) { sum += 0xffffffffL & x; }
    int average = (int)(sum/x.length); // average is now "correct" (bit-for-bit)
    Maybe it wasn't clear that I need to not only load the values but use them.You did fail to mention that.
    The files I load get passed on to other applications where the values get used and obviously that includes doing calculations on them so the values have to be correct. I cannot load a bunch of UInt32s into Java ints and say "pretend they are positive numbers".I get the impression you are not really interested in finding solution.
    It can be releasing to have a whinge but don't let it distract you from thinking outside the box.
    I think part of the problem here is that Java programmers do not have to work with binary files or binary protocols so they do not appreciate that doing this has serious problems in Java.I have done binary protocols. Not having unsigned scalars was never a problem.
    For example, take unsigned longs. If you are working with a binary source that has these you have no alternative except to use the BigInteger package and convert every value into an object, an incredibly painful and CPU-intensive operation if you dealing with files with gigabytes of data.You might want to consider alternatives, like
    unsigned right-shifting ('>>>') the incoming values for 64-bit scalar fields where dividing by 2 would be acceptable,
    etc.

  • Converting jlong to unsigned long

    Hi Everyone,
    I am calling a interface from a dll file which need a unsigned long or long as a parameter. In the C program side, how can I convert the jlong to unsigned long or long and then call the interface from the dll file? Also, how can I convert the long back to jlong and return back to Java side? Thank you.
    Jacky

    Straight cast - BigInteger would be overkill.

  • Parsing binary file- unsigned longs

    Hello everyone.
    I'm currently trying to write a quick parser for a binary file format (ASF). However, java's handling of bit shifting and lack of unsigned types is driving me completely mad.
    How can I represent an unsigned long?
    How can I set the bits for it anyway? It seems that the shift operator can't shift more than an int's worth (it just loops around and starts adding to the other bits- weird).
    Thanks in advance.
    Simon

    ejp wrote:
    But why in the world does the following code also do nothing?
    long x = 45 << 32;
    Try long x = 45L << 32;
    The answer appears to be that java uses ints to represent all constants, but this presents some serious problems- namely- how on earth do you get a number bigger than an int into a long?With 'L'. Same as in C or C++. In Visual Basic it's '&'. There's generally something.Where did that come from? Why have I never seen anything like that before?
    If I do long x = 0x7FFFFFFF; all is well, but if I do long x = 0x80000000; I get FFFFFFFF80000000, which isn't what I asked for.Actually it is exactly what you asked for. You've overlooked several facts: (i) Java longs are 64 bits; (ii) you specified a negative 32-bit constant; (iii) the rules of every programming language I can think of provide for sign-extension when going from a shorter to a longer type.Right. It makes sense now that I know how to specify long constants.
    As someone pointed out signed/unsigned is actually the same, so long as you interpret it correctly. So to avoid the total stupidity of using twice as much memory for everything I've decided that I am actually going to use the correct types.They're not the correct types. As I pointed out in an earlier post, your 'unsigned longs' must be coming from C or C++ where they are generally 32 bits, so using a 64-bit Java long is incorrect.Where they came from doesn't matter. The spec doesn't say it's a "long"- it says that this particular value is 64bit, and that all values are unsigned. So I do need a Java long.
    WHY IN THE WORLD IS JAVA "INTELLIGENT" WHEN DOING THINGS BITWISE? WHICH BRAIN DEAD IDIOT THOUGHT THAT UP? That is broken and is asking for trouble.It is you who is asking for trouble here. The rules of Java are consistent and in conformity with the practice in other programming languages. You've just overlooked several relevant facts.I think I've worked out where I was going wrong here. When doing something like
    int i;
    long x;
    x = x | i;The i is converted to a long before the bitwise operation, so it's not the bitwise operation that's the problem, it's the conversion between int and long?
    It's not Java whose stupidity is the issue here ;-)That wouldn't surprise me.
    Thanks.

  • Signature: FSUpdateOperationStatus(void const*, TCountedPtr TCFURLInfo const&, long long, long long, long long, long long, unsigned long). No support Docs on file for this problem. Multiple crashes on opening Firefax. Running OSX 10.6.4.

    Signature:
    FSUpdateOperationStatus(void const*, TCountedPtr<TCFURLInfo> const&, long long, long long, long long, long long, unsigned long)
    No Support Docs on File.
    Firefox crashes every time it is opened.
    UUID 38fc1438-492f-4ce3-91d4-5ef922101027
    Time 2010-10-27 11:19:32.620395
    Uptime 11
    Last Crash 110 seconds before submission
    Install Age 610295 seconds (1.0 weeks) since version was first installed.
    Product Firefox
    Version 3.6.11
    Build ID 20101012104758
    Branch 1.9.2
    OS Mac OS X
    OS Version 10.6.4 10F569
    CPU x86
    CPU Info GenuineIntel family 6 model 15 stepping 11
    Crash Reason EXC_BAD_ACCESS / KERN_PROTECTION_FAILURE
    Crash Address 0x8
    User Comments
    Processor Notes
    EMCheckCompatibility Fal

    Looking at the crash log it looks like AE might be crashing in:
    net.telestream.wmv.export 
    Can you try uinstalling Flip4Mac (or whatever you have installed from http://www.telestream.net/telestream-products/desktop-products.htm)? You may need to manually go deep into /System to remove them.
    --c

  • How to access variables declared in java class file from jsp

    i have a java package which reads values from property file. i have imported the package.classname in jsp file and also i have created an object for the class file like
    classname object=new classname();
    now iam able to access only the methods defined in the class but not the variables. i have defined connection properties in class file.
    in jsp i need to use
    statement=con.createstatement(); but it shows variable not declared.
    con is declared in java class file.
    how to access the variables?
    thanks

    here is the code
    * testbean.java
    * Created on October 31, 2006, 12:14 PM
    package property;
    import java.beans.*;
    import java.io.Serializable;
    public class testbean extends Object implements Serializable {
    public String sampleProperty="test2";
        public String getSampleProperty() {
            return sampleProperty;
    }jsp file
    <%@ page contentType="text/html;charset=windows-1252"%>
    <%@ page import="java.sql.*,java.util.*"%>
    <html>
    <head>
    <title>Schedule Details</title>
    </head>
    <jsp:useBean id="ConProp" class="property.testbean"/>
    <body>
    Messge is : <jsp:getProperty name="msg" property="sampleProperty"/>
    <%
      out.println(ConProp.sampleProperty);
    %>
    </body>
    </html>out.println(ConProp.sampleProperty) prints null value.
    is this the right procedure to access bean variables
    thanks

  • Converting a Wide String to unsigned long long?

    Hi there,
    I am looking for a way to convert a string to unsigned long long on
    Solaris. On AIX and Linux, there is wcstoull. However, I do not find
    that in solaris. So, I plan to use swscanf ( str, L"%llu", &val).
    However, running thru Rational Purify, each call to swscanf leaks 1
    byte.
    Anyone has a 3rd solution other than the two above? Or maybe there
    is fix to the swscanf leak?
    Thanks in advance,
    Miranda

    % man -s 3C strtoull

  • 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

  • What is top level class declaration in java?

    What is top level class declaration in java?

    The declaration of a class that's not nested inside any other class.

  • How to declare normal java array in fx

    How can we declare normal java array in fx. lets say I extend an abstract java class and it has a method which takes String array as parameter: abstract public void met(String[] users) ;How can i declare String[] parameter while overriding this abstract method in javafx. This does not work: override public function met(s:String[]){ ... }

    Hi,
    The code below works for me:
    public function run(args:String[]){
         var s:String[] = ["Hi", "Hello", "Love", "Peace"];     
         var t:Test2 = Test2{};     
         t.met(s);
    public abstract class Test{
         public abstract function met(s:String[]):Void;
    class Test2 extends Test{
         public override function met(s:String[]):Void{
              for(x in s){
                   println(x);
    }[]'s

  • Taking an array of unsigned word an using it in a subVI that accepts an unsigned long

    I have a user specified sized array that is in unsigned word(16bit). I need to use a subVI, but the subVI only accepts unsigned long(32bit). I was wondering if anyone would know how to make this work.

    Hi Amy;
    Unless I am missing something, there should not be any problem inside LabVIEW.
    To play it safe and keep LabVIEW performance up, convert the array using the "To Unsigned Long Integer" vi located in the function palette:
    Numeric -> Conversion
    Regards;
    Enrique
    www.vartortech.com

  • Should using unsigned long long be this difficult?

    So I have a number. Possibly a big number that I would like to use. When I do the following, valueToGet is fine (1252904880010) when it returns but when I step to currentTimeStamp the value is something like 18446744072483981194.
    I can only assume that maybe I am missing some basic understanding of how methods return this value.
    -(void)processTimestampReceived
    NSString* timeString = @"1252904880010";
    unsigned long long currentTimestamp = [self getUnsignedLongLong: timeString];
    NSLog(@"currentTimeStamp (converted from timeString): %qu", currentTimestamp);
    -(unsigned long long)getUnsignedLongLong:(NSString*)longString
    NSScanner* scanner = [NSScanner scannerWithString:longString];
    unsigned long long valueToGet;
    if([scanner scanLongLong:&valueToGet] == YES) {
    return valueToGet;
    return -1;

    That is so discouraging that code that SHOULD work actually does work for everyone but me. Here is the data after I changed the following code. I had to use scanHexLongLong to actually return an unsigned long long instead of just long long. Is it possible that maybe something is just stomping on that memory location somehow and giving me bad data? But consistently the same way? Seems odd.
    2009-09-14 02:36:37.325 TestApp[46744:20b] lVal=322333076619280
    2009-09-14 02:36:37.530 TestApp[46744:20b] currentTimeStamp (converted from timeString): 322333076619280
    Run using:
    [self processTimestampReceived];
    unsigned long long lVal = [self getUnsignedLongLong:@"1252904880010"];
    NSLog(@"lVal=%qu", lVal);
    -(void)processTimestampReceived
    NSString* timeString = @"1252904880010";
    unsigned long long currentTimestamp = [self getUnsignedLongLong: timeString];
    NSLog(@"currentTimeStamp (converted from timeString): %qu", currentTimestamp);
    -(unsigned long long)getUnsignedLongLong:(NSString*)longString
    NSScanner* scanner = [NSScanner scannerWithString:longString];
    unsigned long long valueToGet;
    if([scanner scanHexLongLong:&valueToGet] == YES) {
    return valueToGet;
    return -1;

Maybe you are looking for

  • Help in add days in Date

    i m working with SAP B1 SP01 and i want to put delivery date in Purchase order with the help of formated search which will get date from docdate and add item lead time in this date. i have write a query for this it works well in sql server but gives

  • HD and Fans

    WOuld switching the internal HD from a 5400 to a 7200 rpm on a MBPro kick start the fans a little more often or is it simply my impression? The unit seems to run a little hotter, but then again, I could be mistaken.

  • Regarding idocs error handling

    HI . i want to learn idoc error handling on sap xi side because  my current project is in PRODUCTION They implemented lot of idocs so is there any documents(guides ) regarding error handling of idocs  for both sender and receiver side.

  • Can any tell difference bt oracle 9i and oracle 10 g

    hi all, i have join oracle 10g course , i have to know it is differnce between oracle 10 g and lower versions. if it topic vise would nice

  • Fix for Flash Player in Internet Explorer Issue

    I've seen quite a few people with this issue and they all seem to have issues finding the fix...I never found a 100% solution on Adobe's site, but I found some directions that finally worked. Basically, if Flash Player refuses to work in Internet Exp