|
Posted by Jim Michaels on 02/12/06 07:00
"Mike" <spam@spam.org> wrote in message
news:UezFf.41982$dW3.40002@newssvr21.news.prodigy.com...
> Okay, start from scratch.
>
>
> Define code
>
> define('CERTACCESS_MEMENTRY', 0x01);
>
>
> Function
>
> function SecurityLevel_Check($security_byte, $securitylevel_bit) {
> //AND = 1 IF BOTH are 1
> echo "<P>SecurityLevel_Check";
> $binanswer = $security_byte & $securitylevel_bit;
> echo "<P>nonbin byte=".$security_byte." /bit=".$securitylevel_bit."
> /nonbin result is ".$binanswer;
> return $security_byte & $securitylevel_bit; }
>
printf("<P>%032b nonbin byte <br>%032b /bit<br>%032b /nonbin result</P>",
$security_byte, $securitylevel_bit, $binanswer);
this will give you binary representation for debug purposes. you can also
check for some stray extra bits. (doubtful. you can change 032 to 08
instead)
>
> $securitylevel_bit is the defines like the one above. The $security_byte
> is the data in the database
> record for a person.
>
>
> Output is
> SecurityLevel_Check
>
> nonbin byte=xFE /bit=2 /nonbin result is 0
>
> SecurityLevel_Check
>
> nonbin byte=xFE /bit=1 /nonbin result is 0
>
> SecurityLevel_Check
>
> nonbin byte=xFE /bit=4 /nonbin result is 0
>
> SecurityLevel_Check
>
> nonbin byte=xFE /bit=8 /nonbin result is 0
>
> SecurityLevel_Check
>
> nonbin byte=xFE /bit=16 /nonbin result is 0
>
> SecurityLevel_Check
>
> nonbin byte=xFE /bit=32 /nonbin result is 0
>
> SecurityLevel_Check
>
> nonbin byte=xFE /bit=128 /nonbin result is 0
>
> SecurityLevel_Check
>
> nonbin byte=0x00 /bit=1 /nonbin result is 0
>
> SecurityLevel_Check
>
> nonbin byte=0x00 /bit=2 /nonbin result is 0
>
> SecurityLevel_Check
>
> nonbin byte=0x00 /bit=4 /nonbin result is 0
>
> SecurityLevel_Check
>
> nonbin byte=0x00 /bit=8 /nonbin result is 0
>
> SecurityLevel_Check
>
> nonbin byte=0x00 /bit=16 /nonbin result is 0
>
>
>
>
>
>
> "Jerry Stuckle" <jstucklex@attglobal.net> wrote in message
> news:DrCdnQAFebQOIXveRVn-tQ@comcast.com...
> Mike wrote:
>> Ah, that is why the result that I am getting. I just posted the function
>> that I created.
>>
>> What is a logical AND? I thought both AND and & were. I'll have to relook
>> at the php docs!
>>
>> Mike
>>
>>
>> "Jerry Stuckle" <jstucklex@attglobal.net> wrote in message
>> news:O--dnZ5sQK4TJXveRVn-hg@comcast.com...
>> Mike wrote:
>>
>>>I made the changes in the database records and in the defines. Same thing
>>>happens. Everything
>>>equates to a 1.
>>>
>>>
>>>"Jerry Stuckle" <jstucklex@attglobal.net> wrote in message
>>>news:y8ydnXXKi4H453jenZ2dnUVZ_sSdnZ2d@comcast.com...
>>>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
>>>>
>>>>
>>>
>>>
>>>x01 is a string containing the characters "x', '0' and '1'.
>>>
>>>0x01 is a one (or more) byte value with the lowest order bit on (and the
>>>rest off).
>>>
>>>
>>
>>
>> Also, "and" is a logical and, not a bit and. Any non-zero value will be
>> true.
>>
>> If you need more help, I suggest you post all the failing code - not
>> just a line or two.
>>
>
> I'm also confused why you're using pack() when you're already working on
> bits.
>
> What exactly are you trying to do, anyway?
>
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstucklex@attglobal.net
> ==================
>
>
>
Navigation:
[Reply to this message]
|