Bitwise operators. Differences from javascript and PHP.

Discussion in 'Python' started by skorobogatov, Nov 17, 2006.

  1. skorobogatov

    skorobogatov Guest

    I can't understand a little thing in bitwise operations.


    In PHP and Javascript
    4653896912>>13 = -212992

    In Python and Ruby
    4653896912>>13 = 568102

    In Python and Ruby - it's ok. I understand.
    But i need to get in Python same value as in PHP and Javascript.
    How can i do this?
     
    skorobogatov, Nov 17, 2006
    #1
    1. Advertisements

  2. True

    not sure what PHP is doing with that expression, really.

    </F>
     
    Fredrik Lundh, Nov 17, 2006
    #2
    1. Advertisements

  3. skorobogatov

    John Machin Guest

    So that someone who knows next-to-nothing about those 2 languages can
    help you, what is x >> n defined to do in PHP and Javascript?

    If you can answer that question, what part of the Python implementation
    of the PHP/Javascript definition are you having trouble with?

    If you can't answer it ... is the problem caused by the fact that
    4653896912 is, at 9 hex digits, a bit large for a 32-bit integer, those
    2 languages don't have longer integers [my guess],
    *and*, to quote something I found about PHP while googling,

    http://theopensourcery.com/phplogic.htm

    "In effect the bitwise operations [words "can be" omitted, I presume]
    safely applied to integer variables - their effect on booleans,
    float/double or string variables can be predicted but are not really
    useful" ???

    Cheers,
    John
     
    John Machin, Nov 17, 2006
    #3
  4. "can only be", more likely.
    sounds like we're in
    -212992

    territory.

    </F>
     
    Fredrik Lundh, Nov 17, 2006
    #4
  5. skorobogatov

    John Machin Guest

    Yes, probably.

    from struct, more likely?
    Sounds like you could be correct. However it's possible that you have
    aided and abetted the OP to perpetrate a nonsense :)

    Cheers,
    John
     
    John Machin, Nov 17, 2006
    #5
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.