Problem with AND &

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jerry Stuckle

    #16
    Re: Problem with AND &

    Mike wrote:[color=blue]
    > Okay, start from scratch.
    >
    >
    > Define code
    >
    > define('CERTACC ESS_MEMENTRY', 0x01);
    >
    >
    > Function
    >
    > function SecurityLevel_C heck($security_ byte, $securitylevel_ bit) {
    > //AND = 1 IF BOTH are 1
    > echo "<P>SecurityLev el_Check";
    > $binanswer = $security_byte & $securitylevel_ bit;
    > echo "<P>nonbin byte=".$securit y_byte." /bit=".$security level_bit." /nonbin result is ".$binanswe r;
    > 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_C heck
    >
    > nonbin byte=xFE /bit=2 /nonbin result is 0
    >
    > SecurityLevel_C heck
    >
    > nonbin byte=xFE /bit=1 /nonbin result is 0
    >
    > SecurityLevel_C heck
    >
    > nonbin byte=xFE /bit=4 /nonbin result is 0
    >
    > SecurityLevel_C heck
    >
    > nonbin byte=xFE /bit=8 /nonbin result is 0
    >
    > SecurityLevel_C heck
    >
    > nonbin byte=xFE /bit=16 /nonbin result is 0
    >
    > SecurityLevel_C heck
    >
    > nonbin byte=xFE /bit=32 /nonbin result is 0
    >
    > SecurityLevel_C heck
    >
    > nonbin byte=xFE /bit=128 /nonbin result is 0
    >
    > SecurityLevel_C heck
    >
    > nonbin byte=0x00 /bit=1 /nonbin result is 0
    >
    > SecurityLevel_C heck
    >
    > nonbin byte=0x00 /bit=2 /nonbin result is 0
    >
    > SecurityLevel_C heck
    >
    > nonbin byte=0x00 /bit=4 /nonbin result is 0
    >
    > SecurityLevel_C heck
    >
    > nonbin byte=0x00 /bit=8 /nonbin result is 0
    >
    > SecurityLevel_C heck
    >
    > nonbin byte=0x00 /bit=16 /nonbin result is 0
    >
    >[/color]
    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.
    jstucklex@attgl obal.net
    =============== ===

    Comment

    • Mike

      #17
      Re: Problem with AND &amp;


      "Jerry Stuckle" <jstucklex@attg lobal.net> wrote in message
      news:jpSdncRvI4 QQpHrenZ2dnUVZ_ t2dnZ2d@comcast .com...
      Mike wrote:[color=blue]
      > Okay, start from scratch.
      >
      >
      > Define code
      >
      > define('CERTACC ESS_MEMENTRY', 0x01);
      >
      >
      > Function
      >
      > function SecurityLevel_C heck($security_ byte, $securitylevel_ bit) {
      > //AND = 1 IF BOTH are 1
      > echo "<P>SecurityLev el_Check";
      > $binanswer = $security_byte & $securitylevel_ bit;
      > echo "<P>nonbin byte=".$securit y_byte." /bit=".$security level_bit." /nonbin result is
      > ".$binanswe r;
      > 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_C heck
      >
      > nonbin byte=xFE /bit=2 /nonbin result is 0
      >
      > SecurityLevel_C heck
      >
      > nonbin byte=xFE /bit=1 /nonbin result is 0
      >
      > SecurityLevel_C heck
      >
      > nonbin byte=xFE /bit=4 /nonbin result is 0
      >
      > SecurityLevel_C heck
      >
      > nonbin byte=xFE /bit=8 /nonbin result is 0
      >
      > SecurityLevel_C heck
      >
      > nonbin byte=xFE /bit=16 /nonbin result is 0
      >
      > SecurityLevel_C heck
      >
      > nonbin byte=xFE /bit=32 /nonbin result is 0
      >
      > SecurityLevel_C heck
      >
      > nonbin byte=xFE /bit=128 /nonbin result is 0
      >
      > SecurityLevel_C heck
      >
      > nonbin byte=0x00 /bit=1 /nonbin result is 0
      >
      > SecurityLevel_C heck
      >
      > nonbin byte=0x00 /bit=2 /nonbin result is 0
      >
      > SecurityLevel_C heck
      >
      > nonbin byte=0x00 /bit=4 /nonbin result is 0
      >
      > SecurityLevel_C heck
      >
      > nonbin byte=0x00 /bit=8 /nonbin result is 0
      >
      > SecurityLevel_C heck
      >
      > nonbin byte=0x00 /bit=16 /nonbin result is 0
      >
      >[/color]
      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.
      jstucklex@attgl obal.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('CERTACC ESS_MEMENTRY', 0x01);) come back as decimal (or so it looks like)? Could that be the
      problem?


      function SecurityLevel_C heck($security_ byte, $securitylevel_ bit) {
      // & = 1 IF BOTH are 1
      echo "<P>SecurityLev el_Check";
      $binanswer = $security_byte & $securitylevel_ bit;
      echo "<P>nonbin byte=".$securit y_byte." /bit=".$security level_bit." /nonbin result is ".$binanswe r;
      return $security_byte & $securitylevel_ bit; }

      SecurityLevel_C heck

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

      SecurityLevel_C heck

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

      SecurityLevel_C heck

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

      SecurityLevel_C heck

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

      SecurityLevel_C heck

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

      SecurityLevel_C heck

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

      SecurityLevel_C heck

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

      SecurityLevel_C heck

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

      SecurityLevel_C heck

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

      SecurityLevel_C heck

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

      SecurityLevel_C heck

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

      SecurityLevel_C heck

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

      SecurityLevel_C heck

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

      SecurityLevel_C heck

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

      SecurityLevel_C heck

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

      SecurityLevel_C heck

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

      SecurityLevel_C heck

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

      SecurityLevel_C heck

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

      SecurityLevel_C heck

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

      SecurityLevel_C heck

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

      SecurityLevel_C heck

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


      SecurityLevel_C heck

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

      SecurityLevel_C heck

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

      SecurityLevel_C heck

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

      SecurityLevel_C heck

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

      SecurityLevel_C heck

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

      SecurityLevel_C heck

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



      Comment

      • Jerry Stuckle

        #18
        Re: Problem with AND &amp;

        Mike wrote:[color=blue]
        > "Jerry Stuckle" <jstucklex@attg lobal.net> wrote in message
        > news:jpSdncRvI4 QQpHrenZ2dnUVZ_ t2dnZ2d@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('CERTACC ESS_MEMENTRY', 0x01);) come back as decimal (or so it looks like)? Could that be the
        > problem?
        >
        >
        > function SecurityLevel_C heck($security_ byte, $securitylevel_ bit) {
        > // & = 1 IF BOTH are 1
        > echo "<P>SecurityLev el_Check";
        > $binanswer = $security_byte & $securitylevel_ bit;
        > echo "<P>nonbin byte=".$securit y_byte." /bit=".$security level_bit." /nonbin result is ".$binanswe r;
        > return $security_byte & $securitylevel_ bit; }
        >
        > SecurityLevel_C heck
        >
        > nonbin byte=0xFE /bit=2 /nonbin result is 0
        >
        > SecurityLevel_C heck
        >
        > nonbin byte=0xFE /bit=1 /nonbin result is 0
        >
        > SecurityLevel_C heck
        >
        > nonbin byte=0xFE /bit=4 /nonbin result is 0
        >
        > SecurityLevel_C heck
        >
        > nonbin byte=0xFE /bit=8 /nonbin result is 0
        >
        > SecurityLevel_C heck
        >
        > nonbin byte=0xFE /bit=16 /nonbin result is 0
        >
        > SecurityLevel_C heck
        >
        > nonbin byte=0xFE /bit=32 /nonbin result is 0
        >
        > SecurityLevel_C heck
        >
        > nonbin byte=0xFE /bit=128 /nonbin result is 0
        >
        > SecurityLevel_C heck
        >
        > nonbin byte=0x00 /bit=1 /nonbin result is 0
        >
        > SecurityLevel_C heck
        >
        > nonbin byte=0x00 /bit=2 /nonbin result is 0
        >
        > SecurityLevel_C heck
        >
        > nonbin byte=0x00 /bit=4 /nonbin result is 0
        >
        > SecurityLevel_C heck
        >
        > nonbin byte=0x00 /bit=8 /nonbin result is 0
        >
        > SecurityLevel_C heck
        >
        > nonbin byte=0x00 /bit=16 /nonbin result is 0
        >
        > SecurityLevel_C heck
        >
        > nonbin byte=0x00 /bit=32 /nonbin result is 0
        >
        > SecurityLevel_C heck
        >
        > nonbin byte=0x00 /bit=64 /nonbin result is 0
        >
        > SecurityLevel_C heck
        >
        > nonbin byte=0x6E /bit=4 /nonbin result is 0
        >
        > SecurityLevel_C heck
        >
        > nonbin byte=0x6E /bit=8 /nonbin result is 0
        >
        > SecurityLevel_C heck
        >
        > nonbin byte=0x6E /bit=16 /nonbin result is 0
        >
        > SecurityLevel_C heck
        >
        > nonbin byte=0x6E /bit=32 /nonbin result is 0
        >
        > SecurityLevel_C heck
        >
        > nonbin byte=0x04 /bit=1 /nonbin result is 0
        >
        > SecurityLevel_C heck
        >
        > nonbin byte=0x04 /bit=2 /nonbin result is 0
        >
        > SecurityLevel_C heck
        >
        > nonbin byte=0x04 /bit=4 /nonbin result is 0
        >
        >
        > SecurityLevel_C heck
        >
        > nonbin byte=0x04 /bit=8 /nonbin result is 0
        >
        > SecurityLevel_C heck
        >
        > nonbin byte=0x04 /bit=16 /nonbin result is 0
        >
        > SecurityLevel_C heck
        >
        > nonbin byte=0x04 /bit=32 /nonbin result is 0
        >
        > SecurityLevel_C heck
        >
        > nonbin byte=0x01 /bit=1 /nonbin result is 0
        >
        > SecurityLevel_C heck
        >
        > nonbin byte=0x01 /bit=2 /nonbin result is 0
        >
        > SecurityLevel_C heck
        >
        > nonbin byte=0x01 /bit=4 /nonbin result is 0
        >[/color]

        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.
        jstucklex@attgl obal.net
        =============== ===

        Comment

        • Mike

          #19
          Re: Problem with AND &amp;


          "Jerry Stuckle" <jstucklex@attg lobal.net> wrote in message
          news:_cKdnZScBv XoZ3renZ2dnUVZ_ s6dnZ2d@comcast .com...
          Mike wrote:[color=blue]
          > "Jerry Stuckle" <jstucklex@attg lobal.net> wrote in message
          > news:jpSdncRvI4 QQpHrenZ2dnUVZ_ t2dnZ2d@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('CERTACC ESS_MEMENTRY', 0x01);) come back as decimal (or so it looks like)? Could that be
          > the
          > problem?
          >
          >
          > function SecurityLevel_C heck($security_ byte, $securitylevel_ bit) {
          > // & = 1 IF BOTH are 1
          > echo "<P>SecurityLev el_Check";
          > $binanswer = $security_byte & $securitylevel_ bit;
          > echo "<P>nonbin byte=".$securit y_byte." /bit=".$security level_bit." /nonbin result is
          > ".$binanswe r;
          > return $security_byte & $securitylevel_ bit; }
          >
          > SecurityLevel_C heck
          >
          > nonbin byte=0xFE /bit=2 /nonbin result is 0
          >
          > SecurityLevel_C heck
          >
          > nonbin byte=0xFE /bit=1 /nonbin result is 0
          >
          > SecurityLevel_C heck
          >
          > nonbin byte=0xFE /bit=4 /nonbin result is 0
          >
          > SecurityLevel_C heck
          >
          > nonbin byte=0xFE /bit=8 /nonbin result is 0
          >
          > SecurityLevel_C heck
          >
          > nonbin byte=0xFE /bit=16 /nonbin result is 0
          >
          > SecurityLevel_C heck
          >
          > nonbin byte=0xFE /bit=32 /nonbin result is 0
          >
          > SecurityLevel_C heck
          >
          > nonbin byte=0xFE /bit=128 /nonbin result is 0
          >
          > SecurityLevel_C heck
          >
          > nonbin byte=0x00 /bit=1 /nonbin result is 0
          >
          > SecurityLevel_C heck
          >
          > nonbin byte=0x00 /bit=2 /nonbin result is 0
          >
          > SecurityLevel_C heck
          >
          > nonbin byte=0x00 /bit=4 /nonbin result is 0
          >
          > SecurityLevel_C heck
          >
          > nonbin byte=0x00 /bit=8 /nonbin result is 0
          >
          > SecurityLevel_C heck
          >
          > nonbin byte=0x00 /bit=16 /nonbin result is 0
          >
          > SecurityLevel_C heck
          >
          > nonbin byte=0x00 /bit=32 /nonbin result is 0
          >
          > SecurityLevel_C heck
          >
          > nonbin byte=0x00 /bit=64 /nonbin result is 0
          >
          > SecurityLevel_C heck
          >
          > nonbin byte=0x6E /bit=4 /nonbin result is 0
          >
          > SecurityLevel_C heck
          >
          > nonbin byte=0x6E /bit=8 /nonbin result is 0
          >
          > SecurityLevel_C heck
          >
          > nonbin byte=0x6E /bit=16 /nonbin result is 0
          >
          > SecurityLevel_C heck
          >
          > nonbin byte=0x6E /bit=32 /nonbin result is 0
          >
          > SecurityLevel_C heck
          >
          > nonbin byte=0x04 /bit=1 /nonbin result is 0
          >
          > SecurityLevel_C heck
          >
          > nonbin byte=0x04 /bit=2 /nonbin result is 0
          >
          > SecurityLevel_C heck
          >
          > nonbin byte=0x04 /bit=4 /nonbin result is 0
          >
          >
          > SecurityLevel_C heck
          >
          > nonbin byte=0x04 /bit=8 /nonbin result is 0
          >
          > SecurityLevel_C heck
          >
          > nonbin byte=0x04 /bit=16 /nonbin result is 0
          >
          > SecurityLevel_C heck
          >
          > nonbin byte=0x04 /bit=32 /nonbin result is 0
          >
          > SecurityLevel_C heck
          >
          > nonbin byte=0x01 /bit=1 /nonbin result is 0
          >
          > SecurityLevel_C heck
          >
          > nonbin byte=0x01 /bit=2 /nonbin result is 0
          >
          > SecurityLevel_C heck
          >
          > nonbin byte=0x01 /bit=4 /nonbin result is 0
          >[/color]

          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(SecurityLeve l_Check($record Set_cert->fields['certcode_acces s'], CERTACCESS_MEMB ERS) == 1) {

          Should I change that to

          if(SecurityLeve l_Check((int)$r ecordSet_cert->fields['certcode_acces s'], CERTACCESS_MEMB ERS) == 1) {

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

          function SecurityLevel_C heck((int)$secu rity_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







          Comment

          • Jerry Stuckle

            #20
            Re: Problem with AND &amp;

            Mike wrote:[color=blue]
            > "Jerry Stuckle" <jstucklex@attg lobal.net> wrote in message
            > news:_cKdnZScBv XoZ3renZ2dnUVZ_ s6dnZ2d@comcast .com...
            > Mike wrote:
            >[color=green]
            >>"Jerry Stuckle" <jstucklex@attg lobal.net> wrote in message
            >>news:jpSdncRv I4QQpHrenZ2dnUV Z_t2dnZ2d@comca st.com...
            >>Mike wrote:
            >>
            >>Ah, I did not catch that since I changed the user records. It puzzled me then I remembered DUH!
            >>the
            >>organizatio n 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('CERTA CCESS_MEMENTRY' , 0x01);) come back as decimal (or so it looks like)? Could that be
            >>the
            >>problem?
            >>
            >>
            >>function SecurityLevel_C heck($security_ byte, $securitylevel_ bit) {
            >>// & = 1 IF BOTH are 1
            >>echo "<P>SecurityLev el_Check";
            >>$binanswer = $security_byte & $securitylevel_ bit;
            >>echo "<P>nonbin byte=".$securit y_byte." /bit=".$security level_bit." /nonbin result is
            >>".$binanswe r;
            >>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[/color]
            >[color=green]
            > >[/color]
            >
            > 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(SecurityLeve l_Check($record Set_cert->fields['certcode_acces s'], CERTACCESS_MEMB ERS) == 1) {
            >
            > Should I change that to
            >
            > if(SecurityLeve l_Check((int)$r ecordSet_cert->fields['certcode_acces s'], CERTACCESS_MEMB ERS) == 1) {
            >
            > so it becomes an integer? Okay, tried that and it did not work. This also did not work.
            >
            > function SecurityLevel_C heck((int)$secu rity_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
            >
            >
            >
            >
            >
            >
            >[/color]

            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.
            jstucklex@attgl obal.net
            =============== ===

            Comment

            • Jim Michaels

              #21
              Re: Problem with AND &amp;


              "noone" <noone@nowhere. com> wrote in message
              news:gyeFf.2225 2$Jd.8308@newss vr25.news.prodi gy.net...[color=blue]
              > Mike wrote:[color=green]
              >> 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('CERTACC ESS_MEDALS', x01);[/color][/color]

              php syntax for hex is 0x01 just as in C/C++.
              [color=blue][color=green]
              >>
              >> Then I run the data through a function
              >>
              >> function SecurityLevel_C heck($security_ byte, $securitylevel_ bit) {
              >> //AND = 1 IF BOTH are 1
              >> return $security_byte And $securitylevel_ bit; }[/color][/color]

              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?
              [color=blue][color=green]
              >>
              >> if(SecurityLeve l_Check($record Set_cert->fields['certcode_acces s'],
              >> CERTACCESS_MEDA L) == 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
              >>
              >>[/color]
              >
              > 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.[/color]


              Comment

              • Jim Michaels

                #22
                Re: Problem with AND &amp;


                "Mike" <spam@spam.or g> wrote in message
                news:UezFf.4198 2$dW3.40002@new ssvr21.news.pro digy.com...[color=blue]
                > Okay, start from scratch.
                >
                >
                > Define code
                >
                > define('CERTACC ESS_MEMENTRY', 0x01);
                >
                >
                > Function
                >
                > function SecurityLevel_C heck($security_ byte, $securitylevel_ bit) {
                > //AND = 1 IF BOTH are 1
                > echo "<P>SecurityLev el_Check";
                > $binanswer = $security_byte & $securitylevel_ bit;
                > echo "<P>nonbin byte=".$securit y_byte." /bit=".$security level_bit."
                > /nonbin result is ".$binanswe r;
                > return $security_byte & $securitylevel_ bit; }
                >[/color]

                printf("<P>%032 b 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)
                [color=blue]
                >
                > $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_C heck
                >
                > nonbin byte=xFE /bit=2 /nonbin result is 0
                >
                > SecurityLevel_C heck
                >
                > nonbin byte=xFE /bit=1 /nonbin result is 0
                >
                > SecurityLevel_C heck
                >
                > nonbin byte=xFE /bit=4 /nonbin result is 0
                >
                > SecurityLevel_C heck
                >
                > nonbin byte=xFE /bit=8 /nonbin result is 0
                >
                > SecurityLevel_C heck
                >
                > nonbin byte=xFE /bit=16 /nonbin result is 0
                >
                > SecurityLevel_C heck
                >
                > nonbin byte=xFE /bit=32 /nonbin result is 0
                >
                > SecurityLevel_C heck
                >
                > nonbin byte=xFE /bit=128 /nonbin result is 0
                >
                > SecurityLevel_C heck
                >
                > nonbin byte=0x00 /bit=1 /nonbin result is 0
                >
                > SecurityLevel_C heck
                >
                > nonbin byte=0x00 /bit=2 /nonbin result is 0
                >
                > SecurityLevel_C heck
                >
                > nonbin byte=0x00 /bit=4 /nonbin result is 0
                >
                > SecurityLevel_C heck
                >
                > nonbin byte=0x00 /bit=8 /nonbin result is 0
                >
                > SecurityLevel_C heck
                >
                > nonbin byte=0x00 /bit=16 /nonbin result is 0
                >
                >
                >
                >
                >
                >
                > "Jerry Stuckle" <jstucklex@attg lobal.net> wrote in message
                > news:DrCdnQAFeb QOIXveRVn-tQ@comcast.com. ..
                > Mike wrote:[color=green]
                >> 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@attg lobal.net> wrote in message
                >> news:O--dnZ5sQK4TJXveRV n-hg@comcast.com. ..
                >> Mike wrote:
                >>[color=darkred]
                >>>I made the changes in the database records and in the defines. Same thing
                >>>happens. Everything
                >>>equates to a 1.
                >>>
                >>>
                >>>"Jerry Stuckle" <jstucklex@attg lobal.net> wrote in message
                >>>news:y8ydnXX Ki4H453jenZ2dnU VZ_sSdnZ2d@comc ast.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('CER TACCESS_MEDALS' , x01);
                >>>>
                >>>>Then I run the data through a function
                >>>>
                >>>>function SecurityLevel_C heck($security_ byte, $securitylevel_ bit) {
                >>>>//AND = 1 IF BOTH are 1
                >>>>return $security_byte And $securitylevel_ bit; }
                >>>>
                >>>>if(Security Level_Check($re cordSet_cert->fields['certcode_acces s'],
                >>>>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).
                >>>
                >>>[/color]
                >>
                >>
                >> 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.
                >>[/color]
                >
                > 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@attgl obal.net
                > =============== ===
                >
                >
                >[/color]


                Comment

                Working...