Adding two possitive numbers results a negative????

Hello everybody i posted that in an other subforum but i guess it was the wrong place. I have a strange problem that it's racking my brain! i have the following code for (int i=0;i<ascii.length;i++){
int randNum=rand.nextInt(100000000);
buffer=randNum*256+ascii[i];
(ascii[i] is an array of four integers that picture an ascii characters).
Normaly that would result a buffer full of positive numbers.In my case thats not always true. Many times i get as a result a negative number even if the other two numbers that i add are positive. What's wrong here?? Thanks in advance!

Integer.MAX_VALUE is 0111 1111 1111 1111 1111 1111 1111 1111
Add one to it, and you wrap around to Integer.MIN_VALUE: 1000 0000 000 0000 0000 0000 0000 0000 (-2 billionish)
Keep addiing, and you end up at -1: 1111 1111 1111 1111 1111 1111 1111 1111
http://en.wikipedia.org/wiki/Twos_complement

Similar Messages

  • Adding two double numbers is a problem

    Hi friends..
    when we try to add the two double numbers say,
    119.52, 10.00
    here we should get 129.52
    but it is giving as 129.51999999999998
    Here i want to round this to two digits after decimal point
    if i round the above value i will get 129.52 and the problem will be solved.
    But we don't know exactly on what basis we are getting the sum as 129.51999999999998.
    Assume that, tomorrow when we are adding some other numbers we may got like
    129.51444444444448
    when we round this we get 129.51
    but actually we have to get 129.52.
    If anyone know why the system is giving that wrong sum amount, please give solution to avoid this.
    To solve this problem, i tried by converting the double numbers to integers and adding these integers and finally converting the sum into double...like
    if
    d1= 119.52
    d2=10
    int x = (int)(119.52*100.00);
    int y = (int)(10.00*100.00);
    int z = x + y;
    double d = (double)(z)/100;
    This is working for this case...
    But when we are applying this approch to other numbers it is giving problem....
    i.e, if i convert like below
    int x = (int)(72.46*100.00);
    this should give x=7246
    but it is giving x=7245
    What is the solution for this problem...please give immediate reply.....

    Assume that, tomorrow when we are adding some other
    numbers we may got like129.51444444444448
    That isn't going to happen. The numerical computations are deterministic. The problem lies in your understanding of how numbers work.
    This has been repeated before so if you want more detail I suggest you search the forums for discussion on precision and double.
    Computers store numbers in binary. The number you are trying to represent is a decimal number. This produces an error in precision.
    The same problem exists in decimal notation. Decimal notation can not accurately represent one divided by three (in decimal 0.33333333.....).

  • Adding two special double numbers

    Adding two double numbers.
    say, 12543.34 and 42895.00 am getting in the decimal part .3999999.
    Now I want .34 instead .399999 and how??
    Can any body help me ??

    Read this (or search the forums--this question is asked at least once a day):
    http://docs.sun.com/source/806-3568/ncg_goldberg.html

  • SMS... iPhone spontaneously adding 1 to phone numbers, resulting in error

    I have all of my contact phone numbers stored as 10 digit numbers.
    Recently, when texting to some of these contacts, the iPhone has started adding the extra digit "1" before the phone numbers, resulting in error messages, and undelivered text messages.
    What gives? Has anyone else had this problem?

    you can do this with apple script.
    Paste the following into Script Editor and run it.
    <pre style="
    font-family: Monaco, 'Courier New', Courier, monospace;
    font-size: 10px;
    margin: 0px;
    padding: 5px;
    border: 1px solid #000000;
    width: 720px;
    color: #000000;
    background-color: #ADD8E6;
    overflow: auto;"
    title="this text can be pasted into the Script Editor">
    tell application "Address Book"
    set NP to number of people
    repeat with i from 1 to NP
    set pers to person i
    repeat with cphone in phones of pers
    if value of cphone is not equal to "" then
    set cur_phone to value of cphone
    set value of cphone to "1" & cur_phone
    end if
    end repeat
    end repeat
    end tell</pre>

  • Error adding up 5 numbers! (or is it me?!)

    Hi -
    I've set Numbers to add up a column of 5 numbers and put the total in a different cell. But it's adding up the numbers wrongly. Can anyone tell me what I'm doing wrong?
    I've put a screenshot on my Public iDisk:
    https://public.me.com/glovepuppet/
    (It's the .jpg called NumbersMOZ001)
    The formula is shown as SUM(H2:H8) which makes 556.02, so why has it put the total as 556.00?
    (I know it's only 2p, but it's irritating!)
    Help please!
    Andy

    This behavior was described many many times.
    The values which you sum are the result of calculations.
    I guess that you use =my_formula
    which may return values with more than two decimal digits.
    When you ask a cell to display two decimal digits, it displays the rounded value *_but, happily, it doesn't change the stored value_*
    So you aren't summing what you see but what is stored.
    Here is your error.
    To sum what you see, you must design formulas whose result is what you see.
    =ROUND(my_formula,2) is what you need.
    So, to be short,
    Numbers did perfectly what you urged it to do.
    Next time, before writing formulas remember that *_computers are just efficient idiots_*.
    Yvan KOENIG (VALLAURIS, France) vendredi 26 novembre 2010 17:26:43

  • Two different retrieval results on two spreadsheets for same account

    I am encountering some very bizarre retrieval behavior that I've never seen before. The version is 11.1.1.3. I have a dynamically calculated account, which produces a Contract-to-date value for Net Sales.
    The formula is:
    IF(@ISMBR("Jan"))
    @MDSHIFT("CTD Sales", 24, "Period", , -1, "Years", ) + "Net Sales";
    ELSE
    @PRIOR("CTD Sales") + "Net Sales";
    It's always worked correctly as far as I can determine. I took a copy of the outline and put it in my dev system and have been working on some other development. In testing, I noticed that my CTD Sales wasn't retrieving the correct number. This is on a spreadsheet with multiple other accounts on it. It works fine up through FY12, then in January of FY13 and thereafter, produces incorrect numbers, with no apparent pattern of error. So I put just the Net Sales and CTD Sales members onto another spreadsheet, without all of the other stuff, and retrieved that, and it produced the correct numbers. It's not a matter of having a spreadsheet formula in the retrieval spot that I've forgotten about (I've done that before). I also copied the spreadsheet with the wrong numbers, and retrieved in Smart View (was retrieving in Essbase add-in before), and got the same wrong numbers.
    In addition, I actually have three dynamically calculated CTD accounts on the sheet, and the bizarre behavior is happening for all three. With all of the other accounts on the sheet, wrong numbers. With only those accounts on the sheet, correct numbers.
    Also, for more information, one of my calculation scripts uses these CTD members, and it is producing the correct result, so this appears to be isolated purely to spreadsheet retrieval.
    So how can the same exact dimension intersection produce two different numbers on two different spreadsheets? Why would having other account members on a spreadsheet affect the results of one of the accounts? Has anyone ever encountered this before?
    Sabrina

    are you sure you have same combinations from rest of dimensions in both spreadsheets...like retrieving for same month ???Absolutely, 100% sure.
    Also does the difference exists for all months retrieval or only for Jan retrieval?It starts in January and the difference continues for the rest of the months/years after. The amount it's off by changes each year, but remains the same for each month in the year. So Jan through Dec of FY13 are all off by 50,321,000. Jan through Dec of FY14 are all off by 186,378,000. Jan through Dec of FY15 are all off by 351,757,000.
    Also note that if you have a retrieval as shown in the screenshot in the following link... for the last 5 months (AUG to DEC) under FY11 will actually retreive for FY12. this is a wierd behaviour.No, I have the year above each month.
    Sabrina
    Edited by: SabrinaD on Aug 3, 2010 12:31 PM

  • How to divide two int numbers and get a fraction ?

    I am dividing two int numbers and the result should be a fraction but I am always getting a zero
    set @result= @num1/@num2  
    when num1=50 and num2=100

    I am dividing two int numbers and the result should be a fraction but I am always getting a zero
    set @result= @num1/@num2  
    You can either one of the values as a decimal or float type, or just multiply one of the values by 1.0.
    set @result= @num1/@num2*1.0
    Dan Guzman, SQL Server MVP, http://www.dbdelta.com

  • How can I get two missing numbers on a iTunes card

    How can I get two missing numbers on a iTunes card

    "Get help",just below the form space where I entered the code. Once I clicked "Get Help", it added another line to the form where I could enter  THE NUMBER ON THE BOTTOM LEFT CORNER on the back of the card. I entered as much of the I scratch-off code I could read, along with the serial number.

  • I have two phone numbers in facetime want to remove one

    i have two phone numbers on facetime want to remove one.

    Settings>facetime> remove the number under the "You can be reached for video calls at" Option.

  • Is it possible to use a single iPhone with two contact numbers via dual sim or an app?

    Is it possible to use a single iPhone with two contact numbers via dual sim or an app?
    This would be a useful feature for personal and company numbers but using one mobile, rather than carrying two devices or diverting calls.

    Then go ahead and try it.  You'll find it's probably a load of crap.
    You want 2 numbers, then use Google Voice or TalkaTone
    Those are US based only Apps or numbers so no good. I won't be wasting money by just trying something either, especially because using a dual sim would mean purchasing another sim card on either pay as you go or monthly contact.

  • My assistant and I are using two Lightrooms (i.e. two serial numbers) and need to share between our two computers. I provide originals to her onto a flash drive. She tags them and returns them to me. I then copy the photos from her flash drive onto my com

    My assistant and I are using two Lightrooms (i.e. two serial numbers) and need to share between our two computers. I provide originals to her onto a flash drive. She tags them and returns them to me. I then copy the photos from her flash drive onto my computer and load them in my LR. The photos appear but witthout any editing or tagging. We need to be able to have her working on the photos on her computer with her copy of LR and me on my computer with my version of LR being able to access what is already tagged and given back to me. This seems hard. We need advice on if it is at all possible to have two computers simultaneously working on LR . I bought her her own version because I was told at the time of purchasing that that was the only way to share. Please advise urgently! Thanks.

    Sounds like your assistant isn't instructing Lightroom to write the tagging and editing to the files themselves, so wehn the files return to you, they don't have editing and tagging information. She need to select the photos in Lightroom and then Ctrl-S (Cmd-S on Mac). Or alternatively turn on the option to autmoatically write this information to the files.
    If you are using RAW photos, then this information will be written to a sidecar XMP file, and your assistant must provide you with the sidecar file. If these photos are not RAW photos, then the information is written directly into the photo file itself.
    Lightroom wasn't designed to be a multi-user program, and so it is truly not possible to have two people working on the same catalog at once. The way you are doing things, as modified above, is probably the way to go.
    As an alternative, you can transfer (portions of) catalogs as well as photos back and forth and then all of these issues disappear, but a catalog might be rather large for a flash drive (or maybe not, it depends)

  • When using private browsing to view image results in Safari 5.1.3, only the first two rows of results are visible, the following four or so rows display greyed out place holders, and the safe search button is inoperable. Suggestions?

    When using private browsing to view image results in Safari 5.1.3, only the first two rows of results are visible, the following four or so rows display greyed out place holders, the remainder of the results page is blank, and the safe search button is inoperable. When I turn off private browsing and refresh the page, everything works again.
    Anyone else having this problem?

    I have got the same behaviour after the last Safari Update to 5.1.3. It seems that Safari now handles some scripts in a new way. If you debug the Google Website, you will see, that there is some Javascript Error, that seems to prevent to write into local cache. After some searching I wasn't able to finde a solution for this problem, other then disabling Javascript while private browsing to prevent the script loading. You then are able to use Google with the old layout. The option to disable JavaScript can be found in the Menu "Developer", wich has to be enabled in Safari in the options first.
    In my opinion this is a bug that is now occuring, because Apple changed something in private browsing and that has to be fixed by Google now, to run again. Or we will have to wait for 5.1.4, as you can read online Apple will change and bugfix the javascript engine in that version, perhaps this fixes the problem as well. I hope so!
    If anyone is in the developer program perhaps you could test this with the beta of 5.1.4 and tell us if it works.

  • My Nokia Lumia 800 has two IMEI numbers. What?!

    Hi Everyone,
    Purchased a Lumia 800 (white) from Nokia Store here in Bangalore, India on August 2012. The phone was working fine till August 2013 when camera stopped working. Took the phone to Nokia Care. Warranty checked out fine and the camera module had to be replaced. Got call from Nokia Care three weeks later saying there has been IMEI mismatch as such warranty is now void. Reason- the phone has two IMEI numbers. What??
    And funny, Nokia's story was true. IMEI number written on the phone panel and phone box differed from internal hardware IMEI number (which can also be seen from Settings>About). They say this can only happen if the phone was serviced earlier and component changed. Well, this was my first time servicing the phone and when the phone is under warranty why will I give for servicing to a non-nokia centre?? This shocked me, I could not convince Nokia people so I just agreed to pay for the repair. Now, after 3 days, they call up and say- "Changed the camera module but it is still not working. Maybe your motherboard is damaged! you will be charged 80% of the phones price if you agree with repair". I am yet to give them the 'go ahead'.
    For no fault of mine I am going through so much!! Is it possible that Nokia sold me a device with two IMEI numbers?? Can anyone please tell me what to do?? Thanks.

    Nokia wouldn't have sold a device in that state. It's highly likely that the retailer is to blame for this one. They've probably sold you a refurbished or repaired set as new.
    If I was you I would go and speak to the retailer about this.

  • To enter two VAT numbers for one vendor in the same country

    Hello All,
    When we try to enter two VAT numbers for one vendor in the master record and belongs to the same country, the system is not allowing and gives the following message,
    "VAT reg.no. already exists for country BE"
    Message no. F2140
    Kkindly let me know the way to proceed further.
    Many thanks in advance.

    Hello,
    Go to OBA5 and switch off the message for online and batch entries.
    If the message is already not there in OBA5,
    Then go to OBMSG and switch off the same.
    Application Area F2
    Message No.140
    Regards,
    Ravi

  • I accidentally added two .doc files, they show in iTunes file sharing, but don't show on iPad?

    I accidentally added two .doc files by dragging and dropping into itunes, under my device, then the app tab, then file sharing for Adobe Reader, they show in iTunes file sharing window, but don't show on iPad 3, and I cannot delete them on iTunes screen? Please help!

    First, I would advise you to apply Tao philosophy to this. Given the dysfunction of most software, if this was just an accidental copy and you don't want them on iPad and they are not showing up anyway, what's the problem? Forget it. It's not worth the hassles. I'm more concerned that you have psychological issues you need to be dealing with, not this. You are making much too unnecessary work and stress for yourself.
    As for deleting them, I'm assuming you highlighted them and hit delete and it didn't work. If not, it should. Works for me. But if it doesn't, my advice is also not to worry about it, as annoying as the clutter is. It will eventually resolve itself (like when your data files corrupt or your iPad crashes, LOL. (I apologize for my cynicism but I am fed up with dysfunctional software). It's not worth the hassles of trying to figure out petty issues.
    As for me, I have the opposite, and very serious problem. I've got Reader on my iPad too. But I can't move the pdfs out of it and onto my laptop with iTunes' dysfunctional file sharing. I get the error "file cannot be copied because you do not have permission to see its contents." I have hundreds of pdfs on my iPad that I converted from web surfing with other programs that also don't work and I can't get them off the iPad for backup and to have a synced library I can access from both laptop and iPad.
    I called iTunes twice and both times they blamed it on the app, saying iTunes file sharing doesn't support third party apps and that I should call Adobe and talk them into writing the code that will work with iTunes. Yeah, right. And Reader is not the only problem. This is happening with iAnnotate and Write PDF and other apps.
    I suspect that both of us have the root problem, perhaps Apple's greedy refusal to support the apps that it sells in the app store and are quasi-integrated enough to show up in the file sharing documents list, but can't be moved or deleted; and the apps that don't bother to make their apps fully work with iTunes file sharing.
    If anyone has any solutions ......

Maybe you are looking for

  • Request in a SessionBean

    Hello all !!! I am developing an application with File Upload, using the Java Creator ONE based in servelet.com. In the example below, the archive is moved successfully, but I would like to have the name of the archive in a SessionBean for use in ano

  • Activity Management  in CRM

    Dear Sir, Can we create the template for Activity Management in CRM ? It look like that when we create the new activity , we will select the tempalte 1, there will be showed the wording in NOte. when we select the template 2 , there will be showed th

  • 5233 Memory card stopped working!

    Hi, I've had this phone for almost a year, it's good but there have been few problems. I have an 8 GB memory card, which I had to reformat recently. Today I was downloaded a theme from nokia store. But suddenly my memory card stopped working. I re -i

  • SAN Replication with ZFS

    We have Solaris 10 Oracle database servers, with ZFS filesystems on an HP XP SAN array. We are going to replicate the data to a backup data center using the XP array itself. We will build identical servers at the backup data center. My question is, h

  • Forte 6 Update 1(C++ 5.2 Compiler) Error - iostream,fstream

    HI, I'm trying to compile my application in 5.2 compiler. It used to compile in SC4.2 compiler. It also compiles in compat mode but I need to compile it in standard mode. I'm getting the following error. Any help would be appreciated. /apps/SUNWspro/