Ok cool, I tried the 1, 2, 4, 8, 16, 32 settings and that seems to work. When comparing flags using the bitwise AND (&) the returning value will be either 0 or the value of the defined number you're testing for. $flags = 1 | 2 | 8 | 16 $flags = $flags & 8 = 8 also $flags = $flags & 4 = 0 // since 4 hasn't been assigned above. Thanks for the suggestion! :-) Jim
_____ From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of Pete Sent: Sunday, June 26, 2005 2:19 PM To: [email protected] Subject: Re: [php-list] Bitwise Operations confusion In message <[EMAIL PROTECTED]>, Jim MacDiarmid <[EMAIL PROTECTED]> writes > > >I'm trying to roll my own CMS and have an integer field in my user database >that I want to be able to set bits or turn on and off flags based on what >permissions the user or group has. My test code is below but doesn't seem >to be working for comparison purposes to see if a user has a particular >permission. >Has anyone done anything like this in PHP? Any ideas what I'm doing wrong? > >define('PERM1', 1); >define('PERM2', 2); >define('PERM3', 4); >define('PERM4', 6); >define('PERM5', 8); >define('SOME_PERMS', PERM1 | PERM3 | PERM4 | PERM5); // should be 19 >define('ALL_PERMS', PERM1 | PERM2 | PERM3 | PERM4 | PERM5); > >$flags = ($flags | SOME_PERMS); >echo $flags . "<BR>"; >echo ( $flags & PERM2 ); This is something that I have never tried in this context, but the bits are not 1,2,4,6,8 but 1,2,4,8,16 Also, you might get some ideas from http://www.shawnolson.net/a/601/ who only goes as far as 1,2,4,8 (no 16, but the principle is the same) -- Pete Clark http://www.hotcosta.com http://www.spanishholidaybookings.com Community email addresses: Post message: [email protected] Subscribe: [EMAIL PROTECTED] Unsubscribe: [EMAIL PROTECTED] List owner: [EMAIL PROTECTED] Shortcut URL to this page: http://groups.yahoo.com/group/php-list _____ YAHOO! GROUPS LINKS * Visit your group "php-list <http://groups.yahoo.com/group/php-list> " on the web. * To unsubscribe from this group, send an email to: [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]> * Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service <http://docs.yahoo.com/info/terms/> . _____ [Non-text portions of this message have been removed] Community email addresses: Post message: [email protected] Subscribe: [EMAIL PROTECTED] Unsubscribe: [EMAIL PROTECTED] List owner: [EMAIL PROTECTED] Shortcut URL to this page: http://groups.yahoo.com/group/php-list Yahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/php-list/ <*> To unsubscribe from this group, send an email to: [EMAIL PROTECTED] <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/
