Results 1 to 5 of 5
  1.    #1  
    Hi everyone, I'm trying to develop an app (harder than it looks, but it's been going somewhat smooth until now). I have a problem.

    From what I've read, Javascript treats numbers as 32 bit integers for binary operations (& for example, binary AND). This is great since I'm working with 32 bit values.

    But I have a big nice trouble here:

    If I do an AND operation from 2 values, I get a negative value on the Pre, and a positive value on a 64 bit calculator. Seems like it's overflowing somewhere.

    Could this be a javascript problem? workaroundable? Or I'll better off splitting my values into 16 bit chunks?

    Thanks
    Just remember: If I helped you, press the thanks button!

    Owner of: Pre Sprint, Pre Telcel, Pre Plus AT&T, Pre 2 Unlocked, Pixi Plus AT&T, and 2 TouchPads (my Pre3 was stolen so it won't appear again here).
    Needs: Veer (anyone?)
    Apps: Subnet Calculator, FreeCam, PhotoFun, NuttyPad (work in progress)
    HomeBrew: meta-doctor and Messaging Plugins collaborator
    Twitter: @cesarneg
  2. #2  
    What numbers are you using, and what is their purpose? Without knowing what you want to do, it's kinda hard to tell you how to do it
    Treo 300 > Hitachi G1000 > PPC-6700 > PPC-6800 (Mogul) > PPC-6850 (Touch Pro) > Palm Pre & HTC EVO Optimus V
  3.    #3  
    Network (TCP/IP) numbers.

    Try this:

    192.168.250.10 & 255.255.255.0

    Should return

    192.168.250.0

    Transformed in 32 bit integers goes:

    3232299530 & 4294967040

    If you do the operation on a calculator, you get: 3232299520
    If you do the operation on Javascript for webOS, you get: -1062667776

    There, how do I make javascript honor the 32 bits for both numbers and don't make it overflow?

    Is there something like an "unsigned int" or something that I have to define??

    Thanks!
  4.    #4  
    Turns out Javascript was indeed treating my numbers as signed integers... grrr

    I just had to:

    1. Save my Least Significant Bit
    2. Shift all my bits to the right one bit
    3. Do my AND operation
    4. Shift my bits back
    5. Restore my LSB

    A bit messy, but it should do the trick

    ExecJosh: Bitwise Operations and Unsigned Numbers in Javascript
    Just remember: If I helped you, press the thanks button!

    Owner of: Pre Sprint, Pre Telcel, Pre Plus AT&T, Pre 2 Unlocked, Pixi Plus AT&T, and 2 TouchPads (my Pre3 was stolen so it won't appear again here).
    Needs: Veer (anyone?)
    Apps: Subnet Calculator, FreeCam, PhotoFun, NuttyPad (work in progress)
    HomeBrew: meta-doctor and Messaging Plugins collaborator
    Twitter: @cesarneg
  5. #5  
    Quote Originally Posted by NuttyBunny View Post
    Turns out Javascript was indeed treating my numbers as signed integers... grrr

    I just had to:

    1. Save my Least Significant Bit
    2. Shift all my bits to the right one bit
    3. Do my AND operation
    4. Shift my bits back
    5. Restore my LSB

    A bit messy, but it should do the trick

    ExecJosh: Bitwise Operations and Unsigned Numbers in Javascript
    But don't you have to do the AND op on the sign bit too? I can't test it from this computer but can't you just do the AND op on the signed 32 bit int?
    mobigamedepot.com

Posting Permissions