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

Problem with AND &

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
Feb 5 '06 #1
21 1763
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.
Feb 5 '06 #2
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).
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Feb 5 '06 #3
I made the changes in the database records and in the defines. Same thing happens. Everything
equates to a 1.
"Jerry Stuckle" <js*******@attglobal.net> wrote in message
news:y8******************************@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).
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Feb 6 '06 #4
Mike wrote:
I made the changes in the database records and in the defines. Same thing happens. Everything
equates to a 1.
"Jerry Stuckle" <js*******@attglobal.net> wrote in message
news:y8******************************@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.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Feb 6 '06 #5
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" <no***@nowhere.com> wrote in message news:gy*****************@newssvr25.news.prodigy.ne t...
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.


Feb 6 '06 #6
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" <js*******@attglobal.net> wrote in message
news:O-********************@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" <js*******@attglobal.net> wrote in message
news:y8******************************@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.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Feb 6 '06 #7
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" <js*******@attglobal.net> wrote in message
news:O-********************@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" <js*******@attglobal.net> wrote in message
news:y8******************************@comcast.co m...
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.


Look at the differences between logical operators and bit operators.

Logical operators deal with one value - true or false. Bit operators
deal with each individual bit in the variable separately.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Feb 6 '06 #8
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" <js*******@attglobal.net> wrote in message
news:O-********************@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" <js*******@attglobal.net> wrote in message
news:y8******************************@comcast.co m...
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.
js*******@attglobal.net
==================
Feb 6 '06 #9
Some else suggested that. It is in this message thread.
"Jerry Stuckle" <js*******@attglobal.net> wrote in message
news:Dr********************@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" <js*******@attglobal.net> wrote in message
news:O-********************@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" <js*******@attglobal.net> wrote in message
news:y8******************************@comcast.co m...
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.
js*******@attglobal.net
==================
Feb 6 '06 #10
Under bitwise operators it has the And & as I am using it. That is what I want.

Ah, I see logical. What I am doing is confusing the name of the operator and the operator itself. I
need to use &, NOT AND!

Okay.

With this code

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 & $securitylevel_bit;
$binanswer2 = $binarybyte & $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;
I get this output

SecurityLevel_Check

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

bin byte= /bit= /bin result is 0

the bin byte is unreadsable chars. HOWEVER, I should not be getting a zero result.


"Jerry Stuckle" <js*******@attglobal.net> wrote in message
news:WP******************************@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" <js*******@attglobal.net> wrote in message
news:O-********************@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" <js*******@attglobal.net> wrote in message
news:y8******************************@comcast.co m...
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.


Look at the differences between logical operators and bit operators.

Logical operators deal with one value - true or false. Bit operators
deal with each individual bit in the variable separately.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Feb 6 '06 #11
I am trying to test the setting of bits, each bit representing something that can be done on the
website.
"Jerry Stuckle" <js*******@attglobal.net> wrote in message
news:Dr********************@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" <js*******@attglobal.net> wrote in message
news:O-********************@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" <js*******@attglobal.net> wrote in message
news:y8******************************@comcast.co m...
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.
js*******@attglobal.net
==================
Feb 6 '06 #12
Mike wrote:
Some else suggested that. It is in this message thread.
"Jerry Stuckle" <js*******@attglobal.net> wrote in message
news:Dr********************@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" <js*******@attglobal.net> wrote in message
news:O-********************@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" <js*******@attglobal.net> wrote in message
news:y8******************************@comcast.c om...
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?


Ah, I found it. No, you shouldn't need to pack your data - it's already
bits.

And please don't top post
A: Because it messes up the order in which people normally read text.
Q: Why?
A: Top-posting.
Q: What is the most annoying thing on usenet?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Feb 6 '06 #13
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; }
$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" <js*******@attglobal.net> wrote in message
news:Dr********************@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" <js*******@attglobal.net> wrote in message
news:O-********************@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" <js*******@attglobal.net> wrote in message
news:y8******************************@comcast.co m...
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.
js*******@attglobal.net
==================

Feb 6 '06 #14

"Jerry Stuckle" <js*******@attglobal.net> wrote in message
news:RP********************@comcast.com...
Mike wrote:
Some else suggested that. It is in this message thread.
"Jerry Stuckle" <js*******@attglobal.net> wrote in message
news:Dr********************@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" <js*******@attglobal.net> wrote in message
news:O-********************@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" <js*******@attglobal.net> wrote in message
news:y8******************************@comcast.c om...
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?


Ah, I found it. No, you shouldn't need to pack your data - it's already
bits.

And please don't top post
A: Because it messes up the order in which people normally read text.
Q: Why?
A: Top-posting.
Q: What is the most annoying thing on usenet?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Okay. Sorry.

Mike
Feb 6 '06 #15
Mike wrote:
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; }
$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

Mike,

You're getting closer - but you're still passing the STRING "xFE" as the
first parameter, not a HEX value. When converted to a number for the
bit operations, the string will be converted to zero.

You need to pass a numeric value to the function.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Feb 6 '06 #16

"Jerry Stuckle" <js*******@attglobal.net> wrote in message
news:jp******************************@comcast.com. ..
Mike wrote:
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; }
$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

Mike,

You're getting closer - but you're still passing the STRING "xFE" as the
first parameter, not a HEX value. When converted to a number for the
bit operations, the string will be converted to zero.

You need to pass a numeric value to the function.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Ah, I did not catch that since I changed the user records. It puzzled me then I remembered DUH! the
organization records. So they are now changed.

However, everything still comes back zero. A question I do have is why does the first number
(varbinary(8) in MySQL) come back hex but the second number (PHP code as
define('CERTACCESS_MEMENTRY', 0x01);) come back as decimal (or so it looks like)? Could that be the
problem?
function SecurityLevel_Check($security_byte, $securitylevel_bit) {
// & = 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; }

SecurityLevel_Check

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

SecurityLevel_Check

nonbin byte=0xFE /bit=1 /nonbin result is 0

SecurityLevel_Check

nonbin byte=0xFE /bit=4 /nonbin result is 0

SecurityLevel_Check

nonbin byte=0xFE /bit=8 /nonbin result is 0

SecurityLevel_Check

nonbin byte=0xFE /bit=16 /nonbin result is 0

SecurityLevel_Check

nonbin byte=0xFE /bit=32 /nonbin result is 0

SecurityLevel_Check

nonbin byte=0xFE /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

SecurityLevel_Check

nonbin byte=0x00 /bit=32 /nonbin result is 0

SecurityLevel_Check

nonbin byte=0x00 /bit=64 /nonbin result is 0

SecurityLevel_Check

nonbin byte=0x6E /bit=4 /nonbin result is 0

SecurityLevel_Check

nonbin byte=0x6E /bit=8 /nonbin result is 0

SecurityLevel_Check

nonbin byte=0x6E /bit=16 /nonbin result is 0

SecurityLevel_Check

nonbin byte=0x6E /bit=32 /nonbin result is 0

SecurityLevel_Check

nonbin byte=0x04 /bit=1 /nonbin result is 0

SecurityLevel_Check

nonbin byte=0x04 /bit=2 /nonbin result is 0

SecurityLevel_Check

nonbin byte=0x04 /bit=4 /nonbin result is 0
SecurityLevel_Check

nonbin byte=0x04 /bit=8 /nonbin result is 0

SecurityLevel_Check

nonbin byte=0x04 /bit=16 /nonbin result is 0

SecurityLevel_Check

nonbin byte=0x04 /bit=32 /nonbin result is 0

SecurityLevel_Check

nonbin byte=0x01 /bit=1 /nonbin result is 0

SecurityLevel_Check

nonbin byte=0x01 /bit=2 /nonbin result is 0

SecurityLevel_Check

nonbin byte=0x01 /bit=4 /nonbin result is 0

Feb 6 '06 #17
Mike wrote:
"Jerry Stuckle" <js*******@attglobal.net> wrote in message
news:jp******************************@comcast.com. ..
Mike wrote:

Ah, I did not catch that since I changed the user records. It puzzled me then I remembered DUH! the
organization records. So they are now changed.

However, everything still comes back zero. A question I do have is why does the first number
(varbinary(8) in MySQL) come back hex but the second number (PHP code as
define('CERTACCESS_MEMENTRY', 0x01);) come back as decimal (or so it looks like)? Could that be the
problem?
function SecurityLevel_Check($security_byte, $securitylevel_bit) {
// & = 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; }

SecurityLevel_Check

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

SecurityLevel_Check

nonbin byte=0xFE /bit=1 /nonbin result is 0

SecurityLevel_Check

nonbin byte=0xFE /bit=4 /nonbin result is 0

SecurityLevel_Check

nonbin byte=0xFE /bit=8 /nonbin result is 0

SecurityLevel_Check

nonbin byte=0xFE /bit=16 /nonbin result is 0

SecurityLevel_Check

nonbin byte=0xFE /bit=32 /nonbin result is 0

SecurityLevel_Check

nonbin byte=0xFE /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

SecurityLevel_Check

nonbin byte=0x00 /bit=32 /nonbin result is 0

SecurityLevel_Check

nonbin byte=0x00 /bit=64 /nonbin result is 0

SecurityLevel_Check

nonbin byte=0x6E /bit=4 /nonbin result is 0

SecurityLevel_Check

nonbin byte=0x6E /bit=8 /nonbin result is 0

SecurityLevel_Check

nonbin byte=0x6E /bit=16 /nonbin result is 0

SecurityLevel_Check

nonbin byte=0x6E /bit=32 /nonbin result is 0

SecurityLevel_Check

nonbin byte=0x04 /bit=1 /nonbin result is 0

SecurityLevel_Check

nonbin byte=0x04 /bit=2 /nonbin result is 0

SecurityLevel_Check

nonbin byte=0x04 /bit=4 /nonbin result is 0
SecurityLevel_Check

nonbin byte=0x04 /bit=8 /nonbin result is 0

SecurityLevel_Check

nonbin byte=0x04 /bit=16 /nonbin result is 0

SecurityLevel_Check

nonbin byte=0x04 /bit=32 /nonbin result is 0

SecurityLevel_Check

nonbin byte=0x01 /bit=1 /nonbin result is 0

SecurityLevel_Check

nonbin byte=0x01 /bit=2 /nonbin result is 0

SecurityLevel_Check

nonbin byte=0x01 /bit=4 /nonbin result is 0


Mike,

You're still close. But you're still passing a string as the first
parameter, not a numeric value. Otherwise, printing it out would give
the value 254 instead of 0xfe.

Bit operations are on integer values only. Here it's taking the '0xfe'
as a string and converting it to an integer. But the integer value of
the string is zero - so none of your test work.

You still need to figure out where the strings are coming from. If this
is coming from a database, the column needs to be an integer type. I
suspect you have it as a character type column.

BTW, you're doing find with bottom posting. But you need to either post
before the signature lines or delete them all together. Many news
readers (like Thunderbird) take everything after the signature separator
(dash-dash-space on a line by itself) as part of the signature.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Feb 7 '06 #18

"Jerry Stuckle" <js*******@attglobal.net> wrote in message
news:_c******************************@comcast.com. ..
Mike wrote:
"Jerry Stuckle" <js*******@attglobal.net> wrote in message
news:jp******************************@comcast.com. ..
Mike wrote:

Ah, I did not catch that since I changed the user records. It puzzled me then I remembered DUH!
the
organization records. So they are now changed.

However, everything still comes back zero. A question I do have is why does the first number
(varbinary(8) in MySQL) come back hex but the second number (PHP code as
define('CERTACCESS_MEMENTRY', 0x01);) come back as decimal (or so it looks like)? Could that be
the
problem?
function SecurityLevel_Check($security_byte, $securitylevel_bit) {
// & = 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; }

SecurityLevel_Check

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

SecurityLevel_Check

nonbin byte=0xFE /bit=1 /nonbin result is 0

SecurityLevel_Check

nonbin byte=0xFE /bit=4 /nonbin result is 0

SecurityLevel_Check

nonbin byte=0xFE /bit=8 /nonbin result is 0

SecurityLevel_Check

nonbin byte=0xFE /bit=16 /nonbin result is 0

SecurityLevel_Check

nonbin byte=0xFE /bit=32 /nonbin result is 0

SecurityLevel_Check

nonbin byte=0xFE /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

SecurityLevel_Check

nonbin byte=0x00 /bit=32 /nonbin result is 0

SecurityLevel_Check

nonbin byte=0x00 /bit=64 /nonbin result is 0

SecurityLevel_Check

nonbin byte=0x6E /bit=4 /nonbin result is 0

SecurityLevel_Check

nonbin byte=0x6E /bit=8 /nonbin result is 0

SecurityLevel_Check

nonbin byte=0x6E /bit=16 /nonbin result is 0

SecurityLevel_Check

nonbin byte=0x6E /bit=32 /nonbin result is 0

SecurityLevel_Check

nonbin byte=0x04 /bit=1 /nonbin result is 0

SecurityLevel_Check

nonbin byte=0x04 /bit=2 /nonbin result is 0

SecurityLevel_Check

nonbin byte=0x04 /bit=4 /nonbin result is 0
SecurityLevel_Check

nonbin byte=0x04 /bit=8 /nonbin result is 0

SecurityLevel_Check

nonbin byte=0x04 /bit=16 /nonbin result is 0

SecurityLevel_Check

nonbin byte=0x04 /bit=32 /nonbin result is 0

SecurityLevel_Check

nonbin byte=0x01 /bit=1 /nonbin result is 0

SecurityLevel_Check

nonbin byte=0x01 /bit=2 /nonbin result is 0

SecurityLevel_Check

nonbin byte=0x01 /bit=4 /nonbin result is 0


Mike,

You're still close. But you're still passing a string as the first
parameter, not a numeric value. Otherwise, printing it out would give
the value 254 instead of 0xfe.

Bit operations are on integer values only. Here it's taking the '0xfe'
as a string and converting it to an integer. But the integer value of
the string is zero - so none of your test work.

You still need to figure out where the strings are coming from. If this
is coming from a database, the column needs to be an integer type. I
suspect you have it as a character type column.

BTW, you're doing find with bottom posting. But you need to either post
before the signature lines or delete them all together. Many news
readers (like Thunderbird) take everything after the signature separator
(dash-dash-space on a line by itself) as part of the signature.

As I said in the message, the database column is varbinary(8) in MySQL. The call to the function is

if(SecurityLevel_Check($recordSet_cert->fields['certcode_access'], CERTACCESS_MEMBERS) == 1) {

Should I change that to

if(SecurityLevel_Check((int)$recordSet_cert->fields['certcode_access'], CERTACCESS_MEMBERS) == 1) {

so it becomes an integer? Okay, tried that and it did not work. This also did not work.

function SecurityLevel_Check((int)$security_byte, $securitylevel_bit)

So I went thru the whole database changing varbinary(8) to tinyint. Then I reset the hex values as
ints. Then I ran the test and it looks good!

Thank you for your patience and help. It is GREATLY appreciated.

Mike



Feb 7 '06 #19
Mike wrote:
"Jerry Stuckle" <js*******@attglobal.net> wrote in message
news:_c******************************@comcast.com. ..
Mike wrote:
"Jerry Stuckle" <js*******@attglobal.net> wrote in message
news:jp******************************@comcast.co m...
Mike wrote:

Ah, I did not catch that since I changed the user records. It puzzled me then I remembered DUH!
the
organization records. So they are now changed.

However, everything still comes back zero. A question I do have is why does the first number
(varbinary(8) in MySQL) come back hex but the second number (PHP code as
define('CERTACCESS_MEMENTRY', 0x01);) come back as decimal (or so it looks like)? Could that be
the
problem?
function SecurityLevel_Check($security_byte, $securitylevel_bit) {
// & = 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; }

SecurityLevel_Check

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

SecurityLevel_Check

nonbin byte=0xFE /bit=1 /nonbin result is 0

SecurityLevel_Check

nonbin byte=0xFE /bit=4 /nonbin result is 0

SecurityLevel_Check

nonbin byte=0xFE /bit=8 /nonbin result is 0

SecurityLevel_Check

nonbin byte=0xFE /bit=16 /nonbin result is 0

SecurityLevel_Check

nonbin byte=0xFE /bit=32 /nonbin result is 0

SecurityLevel_Check

nonbin byte=0xFE /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

SecurityLevel_Check

nonbin byte=0x00 /bit=32 /nonbin result is 0

SecurityLevel_Check

nonbin byte=0x00 /bit=64 /nonbin result is 0

SecurityLevel_Check

nonbin byte=0x6E /bit=4 /nonbin result is 0

SecurityLevel_Check

nonbin byte=0x6E /bit=8 /nonbin result is 0

SecurityLevel_Check

nonbin byte=0x6E /bit=16 /nonbin result is 0

SecurityLevel_Check

nonbin byte=0x6E /bit=32 /nonbin result is 0

SecurityLevel_Check

nonbin byte=0x04 /bit=1 /nonbin result is 0

SecurityLevel_Check

nonbin byte=0x04 /bit=2 /nonbin result is 0

SecurityLevel_Check

nonbin byte=0x04 /bit=4 /nonbin result is 0
SecurityLevel_Check

nonbin byte=0x04 /bit=8 /nonbin result is 0

SecurityLevel_Check

nonbin byte=0x04 /bit=16 /nonbin result is 0

SecurityLevel_Check

nonbin byte=0x04 /bit=32 /nonbin result is 0

SecurityLevel_Check

nonbin byte=0x01 /bit=1 /nonbin result is 0

SecurityLevel_Check

nonbin byte=0x01 /bit=2 /nonbin result is 0

SecurityLevel_Check

nonbin byte=0x01 /bit=4 /nonbin result is 0

>


Mike,

You're still close. But you're still passing a string as the first
parameter, not a numeric value. Otherwise, printing it out would give
the value 254 instead of 0xfe.

Bit operations are on integer values only. Here it's taking the '0xfe'
as a string and converting it to an integer. But the integer value of
the string is zero - so none of your test work.

You still need to figure out where the strings are coming from. If this
is coming from a database, the column needs to be an integer type. I
suspect you have it as a character type column.

BTW, you're doing find with bottom posting. But you need to either post
before the signature lines or delete them all together. Many news
readers (like Thunderbird) take everything after the signature separator
(dash-dash-space on a line by itself) as part of the signature.

As I said in the message, the database column is varbinary(8) in MySQL. The call to the function is

if(SecurityLevel_Check($recordSet_cert->fields['certcode_access'], CERTACCESS_MEMBERS) == 1) {

Should I change that to

if(SecurityLevel_Check((int)$recordSet_cert->fields['certcode_access'], CERTACCESS_MEMBERS) == 1) {

so it becomes an integer? Okay, tried that and it did not work. This also did not work.

function SecurityLevel_Check((int)$security_byte, $securitylevel_bit)

So I went thru the whole database changing varbinary(8) to tinyint. Then I reset the hex values as
ints. Then I ran the test and it looks good!

Thank you for your patience and help. It is GREATLY appreciated.

Mike



No problem, Mike,

Yes, varbinary is a character type - basically the difference between
that and varchar in MySQL is the binary types are case sensitive.

I know it is confusing, but that's how things work!

Glad you got it going.

And BTW - this post was perfect!

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Feb 7 '06 #20

"noone" <no***@nowhere.com> wrote in message
news:gy*****************@newssvr25.news.prodigy.ne t...
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);
php syntax for hex is 0x01 just as in C/C++.

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; }
use & instead of and for bitwise operations. echo those values you are
comparing. maybe one of them is a hex string instead of an integer?

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.

Feb 12 '06 #21

"Mike" <sp**@spam.org> wrote in message
news:Ue*******************@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" <js*******@attglobal.net> wrote in message
news:Dr********************@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" <js*******@attglobal.net> wrote in message
news:O-********************@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" <js*******@attglobal.net> wrote in message
news:y8******************************@comcast.c om...
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.
js*******@attglobal.net
==================

Feb 12 '06 #22

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

Similar topics

4
by: johkar | last post by:
When the output method is set to xml, even though I have CDATA around my JavaScript, the operaters of && and < are converted to XML character entities which causes errors in my JavaScript. I know...
2
by: chris | last post by:
Hi there, I create an XML file from a dataset like this: System.IO.StreamWriter xmlSW = new System.IO.StreamWriter(FILENAME); dsUserData1.WriteXml(xmlSW, XmlWriteMode.WriteSchema);...
5
by: comshiva | last post by:
Hi all, I have converted my existing ASP.NET project from 1.1 to 2.0 and i have found that everything works fine except the linkbutton control in my datagrid which throws an javascript error when...
16
by: Dany | last post by:
Our web service was working fine until we installed .net Framework 1.1 service pack 1. Uninstalling SP1 is not an option because our largest customer says service packs marked as "critical" by...
1
by: Joe | last post by:
I want to save some URLs into a XML formatted document. > > I find out that its having some problems due to some of the characters > used > in the URL. > > Is there a quick way to get around...
6
by: comp.lang.php | last post by:
I am trying to pipe in some auto-generated PHP into php.exe, to no avail: catch {exec echo '<? if (@is_file("./functions.inc.php")) { require_once("./functions.inc.php"); echo...
3
by: gg | last post by:
I specify the Url element as <xsd:element name="Url"> <xsd:simpleType> <xsd:restriction base="xsd:string"> <xsd:maxLength value="512"/> <xsd:pattern value="http://+"/> </xsd:restriction>...
3
polymorphic
by: polymorphic | last post by:
I have succeeded in embedding PDF files in a dynamic iframe. The problem is that I need the PDF to cache. If the PDF remains the same from page load to page load then the pdf is somehow cached with...
5
by: Juan R. =?iso-8859-1?q?Gonz=E1lez-=C1lvarez?= | last post by:
I want to substitute "\(" by "(" i have tried content = content.replace(/\\\(/g, "("); content = content.replace(/\\\(/g, unescape("%26") + "#40;"); content = content.replace(/\\\(/g,...
2
by: bvdamme | last post by:
Hello, In my httpd error_log file I get following error : PHP Warning: include(http://filuntu/php/includes/header.php? mask_menu1=1111&amp;mask_menu2=111111&amp;terug=/php/hoofdmenu.php) : failed...
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
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...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.