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? 4 2074 sk**********@gm ail.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>
skoroboga...@gm ail.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
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(465389691 2) from string import pack, unpack o = unpack("i", pack("d", v)[:4])[0] (-o>>(13-3))|-2<<(32-13-1)
-212992
territory.
</F>
On Nov 17, 9:38 pm, Fredrik Lundh <fred...@python ware.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(465389691 2)
>>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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 of 'flags'
for users on a website. The function below is supposed to be a search
function for one of those flags in a particular thing.
The idea is that when something calls userId(), it should get to see
what type of user flags that are...
|
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.
Javascritp has >>> and >>. >>> is a zero fill bit shift whereas >> is
a sign propagating bit shift. My understanding is that the python >>
is equivalent to the javascript >> - but python has no equivalent to
>>>.
Would a >>> 3 in javascript be...
|
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 anyone would use them - any real
world examples or ideas? Examples follow (that I am reading in my Core
JavaScript Guide 1.5).
15 & 9 yields 9 (1111 & 1001 = 1001)
15 | 9 yields 15 (1111 | 1001 = 1111)
15 ^ 9 yields 6 (1111 ^ 1001 = 0110)
in...
|
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 used in hardware programming.
Are they used very often in routine C/C++ programming, and what for?
thanks,
MJH
|
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 programming in straight C, the Win32 API sends
windows messages to applications with various settings stored in bit
fields, in which case changing the settings of the message is a matter
of using the bitwise operators. This was a good practical example of...
| |
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 with 2's complement,
1's complement, or sign-magnitude arithmetic. But the followup
remark is sometimes also made that the choice of arithmetic isn't
completely unconstrained, since the bitwise operators seem to
presume a base-2 machine.
|
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 you will but I
cannot seem to see the purpose for bitwise operators. Especially the
operators bitwise OR ( | ) and bitwise AND ( & ), I'm just not getting
it. I have searched around and really haven't found anything that gave
explanation to why...
|
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 int column used for
bitwise data - you know the sort of thing... 0, 1, 2, 4, 8, 16 etc
intBitwise strName
----------------------
|
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 often done in Python because of keyword
arguments and dicts, which are lot more versatile. Another major use,
talking to hardware, is not something oft done in Python either.
It seems like this occasional usage wouldn't justify having built-in...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |