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

Right Shift

Here's some confusion for you...

<?PHP
$x = (4653896912 >> 13);
echo $x;
?>

I ran that on two different servers.

Server A gave me: 43814
Server B gave me: 568102

I have been hacking away and researching this for hours. I am
completely clueless. Any suggestions or workarounds? Thanks in advance.

Mar 15 '06 #1
10 3163
CrashRoX said the following on 15/03/2006 10:32:
Here's some confusion for you...

<?PHP
$x = (4653896912 >> 13);
echo $x;
?>

I ran that on two different servers.

Server A gave me: 43814
Server B gave me: 568102

I have been hacking away and researching this for hours. I am
completely clueless. Any suggestions or workarounds? Thanks in advance.


4653896912 is bigger than can be represented as a signed-int on a 32-bit
platform, so gets truncated to 358929616. And (358929616 >> 13) == 43814.

However, 4653896912 can be represented as a signed-int on a 64-bit
platform, giving the "correct" answer of 568102.
[NOTE: I haven't checked this to see if it's right though...]

--
Oli
Mar 15 '06 #2
I just figured out that server A is a 32 bit machine and server B is
64. How can I account for this?

Mar 15 '06 #3
Im actually looking for the answer as 43814. Is there no "workaround"
or solution to force a 64 bit machine to generate the same answer?

Mar 15 '06 #4
CrashRoX said the following on 15/03/2006 10:48:
Im actually looking for the answer as 43814. Is there no "workaround"
or solution to force a 64 bit machine to generate the same answer?


Why are you looking for this to be the answer? In some senses,
(4653896912 >> 13) is meaningless on a 32-bit machine.

However, I guess you could do:

$x = 4653896912;
$y = $x & 0xFFFFFFFF;
$z = $y >> 13;

I can't confirm that this will work though, as I don't have access to
64-bit PHP...

--
Oli
Mar 15 '06 #5
CrashRoX wrote:
I just figured out that server A is a 32 bit machine and server B is
64. How can I account for this?


Don't count on values larger than the maximum integer size! It just
creates more bugs.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Mar 15 '06 #6
I know the actual results are meaningless for a 32-bit system. Im
dealing with an application that was designed on a 32bit system and is
being ported to 64. Unfortunately the system was designed to use
results generated from the 32-bit system, regardless if it has meaning.
Oli Filth's suggestion seems to be working. Hopefully it will hold up.

Thank you.

Mar 15 '06 #7
The right "workaround" seems to be doing the job. Will this work the
same way going left?

$x = $a;
$y = $x & 0xFFFFFFFF;
$z = $y << $b;

return $z;

Mar 15 '06 #8
I believe I narrowed down my bug to ZOR. The right and left shifts
seems to be working just fine with the workaround suggested. Any
suggestions for a ZOR workaround?

Mar 15 '06 #9
I believe I narrowed down my bug to XOR. The right and left shifts
seems to be working just fine with the workaround suggested. Any
suggestions for a XOR workaround?

Mar 15 '06 #10
I believe I narrowed down my bug to XOR. The right and left shifts
seems to be working just fine with the workaround suggested.

$b ^= $c

is giving me different results on the 32bit machine and the 64. Im
looking to get the same 32bit answer on the 64bit machine. Any
suggestions for another workaround?

Mar 15 '06 #11

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

Similar topics

8
by: Nick Patavalis | last post by:
Ok, what is this supposed to print: #include <stdio.h> #include <stdint.h> int main (void) { uint32_t r, s;
12
by: DeepaK K C | last post by:
main() { int a =100; a = a>>32; printf(" %d", a); } it prints "a" as 100 only....but I am expecting a = 0..... can some one tell me the reason?
3
by: ERE | last post by:
Pardon me if this has been asked a million times -- but I thought that because of generics, the right shift operator was supposed to change with C# 2.0. I thought it was supposed to change from...
44
by: Viken Karaguesian | last post by:
Hello all, On occasion I want to open hyperlinks (images, etc.) in a new window. In the past, I've used target="_blank" to open the link in a new window. However, using the "target" attribute...
12
by: Mick_fae_Glesga | last post by:
OK, the solution to this is probably blindingly obvious to everyone, but... surely it can't be right. I am compiling with borland bcc32 free compiler this piece of code is designed to identify...
3
by: geraldshastri | last post by:
Hi, I am designing xhtml templates using table-less design with div's and CSS positioning. But the problem is that certain pages tend to shift to the left despite the fact that the underlying...
16
by: Santosh Nayak | last post by:
Hi, Is there any way to catch the losing bit occurring due to Right Shift Operator ? e.g int a = 5 ; a = a >1 ; // // a is now 2 and the least significant bit is lost // // I want this...
4
by: G Iveco | last post by:
I am using this type of code to do right-shifting, B = 3; data1 = (data + (1 << (B-1))) >B; data1 seems incorrect when data = -4-8*i.. which means it rounds -1.5 to -1 instead of -2. On...
5
by: miss time | last post by:
Hi all, I will show you the solution of question , Sometime i have problem in implement the code in BlueJ but i understant what they want frome me in question. this is question 1/ Write a method...
1
by: Anne | last post by:
Hi, How can I in a MDE-file disable the "startup with Right Shift Key" ? I tried it in Options --Startup, but can't get it working. Thanks, Anne
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...
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
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.