473,396 Members | 2,154 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Bitwise operators. Differences from javascript and PHP.

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?

Nov 17 '06 #1
4 2057
sk**********@gmail.com wrote:
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.
hint:
>>4653896912 sys.maxint
True

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

</F>

Nov 17 '06 #2

skoroboga...@gmail.com wrote:
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?
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

Nov 17 '06 #3
John Machin wrote:
http://theopensourcery.com/phplogic.htm

"In effect the bitwise operations [words "can be" omitted, I presume]
"can only be", more likely.
safely applied to integer variables - their effect on booleans,
float/double or string variables can be predicted but are not really
useful" ???
sounds like we're in
>>v = float(4653896912)
from string import pack, unpack
o = unpack("i", pack("d", v)[:4])[0]
(-o>>(13-3))|-2<<(32-13-1)
-212992

territory.

</F>

Nov 17 '06 #4


On Nov 17, 9:38 pm, Fredrik Lundh <fred...@pythonware.comwrote:
John Machin wrote:
http://theopensourcery.com/phplogic.htm
"In effect the bitwise operations [words "can be" omitted, I presume]"can only be", more likely.
Yes, probably.
>
safely applied to integer variables - their effect on booleans,
float/double or string variables can be predicted but are not really
useful" ???sounds like we're in
>>v = float(4653896912)
>>from string import pack, unpack
from struct, more likely?
>>o = unpack("i", pack("d", v)[:4])[0]
>>(-o>>(13-3))|-2<<(32-13-1)
-212992

territory.
Sounds like you could be correct. However it's possible that you have
aided and abetted the OP to perpetrate a nonsense :-)

Cheers,
John

Nov 17 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Michael B. Trausch | last post by:
I have a question regarding bitwise operators, I've been trying to figure this out for about two days now, and I just can't seem to get it. What I'm trying to do is use a variable to hold a bitmask...
2
by: Michael Foord | last post by:
Please pardon my ignorance on this one - but I'm not certain how the sign bt is treated in python bitwise operators. I've trying to convert a javascript DES encryption routine into python. ...
11
by: Randell D. | last post by:
Why would one use bitwise operators? I can program in various languages in some shape or form (C++, PHP, some scripting) and I've heard/seen bitwise operators before, but never understood why...
4
by: Mike Hodkin | last post by:
As a beginning student of C++, books reference "bitwise operators" and give brief examples, but I have not read a good explanation of what they are used for. One reference mentioned that they are...
6
by: jas_lx | last post by:
The basic understanding of what bitwise operators (& ^ | >> << ) comes fairly simple, as long as one has a fundamental understanding of bits, bytes and binary. Having done some Win32...
2
by: Steve Summit | last post by:
-----BEGIN PGP SIGNED MESSAGE----- It's often explained that the reason for some of the imprecision in C's definition is so that C can be implemented on different kinds of machines -- say, those...
5
by: noridotjabi | last post by:
I'm learning to program in C and any tutorial or book that I read likes to briefly touch on birdies operators and then move on without giving any sort of example application of them. Call me what...
2
by: Mark Rae | last post by:
Hi, This isn't *specifically* an ASP.NET question, so I've also posted it in the ADO.NET group - however, it's not too far off-topic... Imagine a SQL Server 2005 database with a table with an...
29
by: Carl Banks | last post by:
Anyone with me here? (I know the deadline for P3 PEPs has passed; this is just talk.) Not many people are bit-fiddling these days. One of the main uses of bit fields is flags, but that's not...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.