473,320 Members | 1,732 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,320 software developers and data experts.

Difference of & in perl and php

Hello,

I'm porting a program from php to perl and discovered, that the bitwise
operator & seems to work differently, which I don't understand why.

I tested it with the values:

a=5543039447 and b=13

Then in perl the expressions:

$result= ($z & $a);

returns 2147483648.

But in php the same expression returns zero. Why is that and how can I
fix it?!

Fritz

Mar 3 '06 #1
3 1596
d
<fr*********@web.de> wrote in message
news:11*********************@z34g2000cwc.googlegro ups.com...
Hello,

I'm porting a program from php to perl and discovered, that the bitwise
operator & seems to work differently, which I don't understand why.

I tested it with the values:

a=5543039447 and b=13

Then in perl the expressions:

$result= ($z & $a);

returns 2147483648.

But in php the same expression returns zero. Why is that and how can I
fix it?!
If you have defined $a and $b, then bitwise-anded $z and $a, you *should*
get zero, as zero AND anything is zero. If, however, you do bitwise-and $a
and $b, you shouldn't get 2147483648 in the first place, so I don't know
where your problem is :)
Fritz

Mar 3 '06 #2

d wrote:
<fr*********@web.de> wrote in message
news:11*********************@z34g2000cwc.googlegro ups.com...
Hello,

I'm porting a program from php to perl and discovered, that the bitwise
operator & seems to work differently, which I don't understand why.

I tested it with the values:

a=5543039447 and b=13

Then in perl the expressions:

$result= ($z & $a);

returns 2147483648.

But in php the same expression returns zero. Why is that and how can I
fix it?!


If you have defined $a and $b, then bitwise-anded $z and $a, you *should*
get zero, as zero AND anything is zero. If, however, you do bitwise-and $a
and $b, you shouldn't get 2147483648 in the first place, so I don't know
where your problem is :)
Fritz


sorry, i messed up the example. I posted a follow up thread, please
forget about this one.

Mar 3 '06 #3

<fr*********@web.de> wrote in message
news:11*********************@z34g2000cwc.googlegro ups.com...
Hello,

I'm porting a program from php to perl and discovered, that the bitwise
operator & seems to work differently, which I don't understand why.

I tested it with the values:

a=5543039447 and b=13

Then in perl the expressions:

$result= ($z & $a);

returns 2147483648.

But in php the same expression returns zero. Why is that and how can I
fix it?!

Fritz


In my perl (ActivePerl 5.8.8.816 in WInXP 32-bit) I get 13 for a result.
5543039447=0x0000 0001 4A64 11D7
it's a 33-bit number, so that may be the cause of your problem right there.
undefined behavior after the bits get too big.
Mar 15 '06 #4

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

Similar topics

13
by: Mattias Campe | last post by:
Hi, Depending on if I get an image or a text of a certain URL, I want to do something different. I don't know in advance whether I'll get an image or a text. This is a URL that returns an...
1
by: Stephen Ferg | last post by:
Seen in the Wall Street Journal, Monday, July 21, 2003, page B1. Lee Gomes' "Portals" technology column: "Two Men, Two Ways to Speak Computerese and Two Big Successes". This is a brief,...
29
by: Bart Nessux | last post by:
Just fooling around this weekend. Wrote and timed programs in C, Perl and Python. Each Program counts to 1,000,000 and prints each number to the console as it counts. I was a bit surprised. I'm not...
19
by: John Keeling | last post by:
Dear all, I tried the test program below. My interest is to examine timing differences between insert vs. append & reverse for a list. My results on my XP Python 2.3.4 are as follows:...
1
by: Justin Kozuch | last post by:
Hi All, How do I determine the path to Perl on a Windows 2000 server? My hosting company has installed ActiveState Perl (latest version). I've called them and they said the path to perl is...
6
by: Mark Rae | last post by:
Hi, I'm not sure if this is the right newsgroup, but here goes... I'm trying to integrate the webwho.zip cgi script from the following site: http://www.webwho.co.uk/ into a standard ASP.NET...
0
by: jbenezech | last post by:
Hi all , I have a perl/java app running under Win32. The application consists of a perl service (Win32::Daemon) and of java classes. The perl service calls every xx hours java classes to perform...
8
by: Palindrom | last post by:
Hi everyone ! I'd like to apologize in advance for my bad english, it's not my mother tongue... My girlfriend (who is a newbie in Python, but knows Perl quite well) asked me this morning why...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.