LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-06-2005, 10:49 AM   #1
rtaft
Member
 
Registered: Aug 2003
Posts: 85

Rep: Reputation: 15
Odd PHP & issue.


I am trying to do bit operations and I am seeing some weird results in PHP. The following code:

Code:
 echo "\n<!-- (".$array2['ID']." & ".$array['divisions'].") = ".($array2['ID'] & $array['divisions'])." == ".$array2['ID']." ::: ".((($array2['ID'] & $array['divisions']) == $array2['ID'])?"TRUE":"FALSE")."-->\n";
Outputs:

Code:
<!-- (8 & 11) = 0 == 8 ::: FALSE-->
I don't understand why be cause obviously 8 & 11 = 8. Sometimes this works fine:
Code:
<!-- (8 & 9) = 8 == 8 ::: TRUE-->
<!-- (4 & 5) = 4 == 4 ::: TRUE-->
Actually it only works fine when b = a+1 when (a & b) = a

Is & actually something else besides AND in PHP?

Last edited by rtaft; 05-06-2005 at 10:50 AM.
 
Old 05-06-2005, 11:24 AM   #2
rtaft
Member
 
Registered: Aug 2003
Posts: 85

Original Poster
Rep: Reputation: 15
Nevermind, I figured it out. I would think PHP would be smart enough to realize that if a database column was of type INT that it would assume the datatype of the variable to be an int. Unfortunately for me 11 was really becoming 0x3131 which anded with 8 is 0, and 9, which is 0x39, anded with 8 is 8. Casting all array variables to ints solved my issue.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
odd mandriva issue goofusbrain Linux - Networking 1 11-13-2005 07:09 PM
PHP & Apache Issue? Plz help! wh33t Programming 1 10-01-2005 06:17 AM
Some... odd (?) issue with Xorg 6.8.2 on CRUX 2.1 Mr. Asdf Linux - Software 5 07-19-2005 10:28 AM
Odd *nix issue with c/c++ Will_C_T Programming 3 09-10-2004 12:17 AM
PHP & Apache2 issue status? theetderks Linux - General 2 01-25-2004 06:34 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:42 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration