You are here: Re: Problem with AND & « PHP Programming Language « IT news, forums, messages
Re: Problem with AND &

Posted by Mike on 02/06/06 04:50

I changed the function code to the following but there was no change.


function SecurityLevel_Check($security_byte, $securitylevel_bit) {
//AND = 1 IF BOTH are 1
$binarybyte = pack("n", $security_byte);
$binarybit = pack("n", $securitylevel_bit);
echo "<P>SecurityLevel_Check";
$binanswer = $security_byte AND $securitylevel_bit;
$binanswer2 = $binarybyte AND $binarybit;
echo "<P>nonbin byte=".$security_byte." /bit=".$securitylevel_bit." /nonbin result is ".$binanswer;
echo "<P>bin byte=".$binarybyte." /bit=".$binarybit." / bin result is ".(int)$binanswer2;
return $security_byte AND $securitylevel_bit; }


I also changed all x00 to 0x00 for all definitions of hex data. What am I doing wrong?

Results are

SecurityLevel_Check

nonbin byte=xFE /bit=2 /nonbin result is xFE

bin byte=







"noone" <noone@nowhere.com> wrote in message news:gyeFf.22252$Jd.8308@newssvr25.news.prodigy.net...
Mike wrote:
> I am having a problem getting AND to work. I have a MySQL database field defined as varbinary(8)
> with X00 in it. Then I have define statements with X01 in it.
>
> define('CERTACCESS_MEDALS', x01);
>
> Then I run the data through a function
>
> function SecurityLevel_Check($security_byte, $securitylevel_bit) {
> //AND = 1 IF BOTH are 1
> return $security_byte And $securitylevel_bit; }
>
> if(SecurityLevel_Check($recordSet_cert->fields['certcode_access'], CERTACCESS_MEDAL) == 1) {
>
>
> No matter what the values are it always returns a 1. I've looked and looked at the docs and cannot
> figure out what I am doing wrong. I tried AND and & and both produce different but wrong results.
>
> PLEASE throw me a bone of a hint at what I am doing wrong.
>
> Thanks.
>
> Mike
>
>

Take a look at the PACK/UNPACK functions in PHP to unpack and convert
the data to a number and do the comparison.

http://us2.php.net/manual/en/function.pack.php
http://us2.php.net/manual/en/function.unpack.php

M.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация