Software Design
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreSoftware Design

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 20th, 2004, 06:06 PM
Nycto's Avatar
Nycto Nycto is offline
coding with style
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Mar 2003
Location: Washington
Posts: 1,254 Nycto User rank is Sergeant Major (2000 - 5000 Reputation Level)Nycto User rank is Sergeant Major (2000 - 5000 Reputation Level)Nycto User rank is Sergeant Major (2000 - 5000 Reputation Level)Nycto User rank is Sergeant Major (2000 - 5000 Reputation Level)Nycto User rank is Sergeant Major (2000 - 5000 Reputation Level)Nycto User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 13 h 46 m 4 sec
Reputation Power: 54
Send a message via ICQ to Nycto Send a message via AIM to Nycto
combining binary numbers

I'm working on a simple PHP permissions function at the moment. Users belong to any number of groups, and those groups have a binary number (saved in base 10) that represents whether they have access to one aspect of the site. It's a common method, but let me give an example just to clarify.

I want to find out if the current user has access to something with permission level of 8... 1000. He belongs to a group that has a permission level of 27... 11011. Thus, he has permission to view the content.

Now, a user can belong to multiple groups. I am looking for an easy method (hopefully a formula) to combine the permission levels of two groups. Say a user belongs to a group with a perm level of 25 (11001) and one of 3 (11). I want 27 spit out (11011).

I've been searching around, but I don't know exactly what to call this. Any help would be appreciated.

5 (101) + 1 (001) = 5 (101)
6 (110) + 5 (101) = 7 (111)
3 (011) + 2 (010) = 3 (011)

Thanks a lot.
__________________
- Nycto

commonPHP: A library for PHP 5.3

Reply With Quote
  #2  
Old June 20th, 2004, 09:25 PM
Nycto's Avatar
Nycto Nycto is offline
coding with style
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Mar 2003
Location: Washington
Posts: 1,254 Nycto User rank is Sergeant Major (2000 - 5000 Reputation Level)Nycto User rank is Sergeant Major (2000 - 5000 Reputation Level)Nycto User rank is Sergeant Major (2000 - 5000 Reputation Level)Nycto User rank is Sergeant Major (2000 - 5000 Reputation Level)Nycto User rank is Sergeant Major (2000 - 5000 Reputation Level)Nycto User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 13 h 46 m 4 sec
Reputation Power: 54
Send a message via ICQ to Nycto Send a message via AIM to Nycto
I found my answer in the form of Bitwise operators.

Reply With Quote
  #3  
Old June 21st, 2004, 03:07 PM
dog135's Avatar
dog135 dog135 is offline
Doggie
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jul 2003
Location: Seattle, WA
Posts: 751 dog135 User rank is Corporal (100 - 500 Reputation Level)dog135 User rank is Corporal (100 - 500 Reputation Level)dog135 User rank is Corporal (100 - 500 Reputation Level)dog135 User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 10 h 38 m 25 sec
Reputation Power: 7
For those who might be reading this, and don't know, the bitwise operator used is "or".

you would write:

newPermission=old1perm|old2perm; (bitwise "or")

1000|0001=1001
1100|1001=1101
__________________
"Science is constructed of facts as a house is of stones. But a collection of facts is no more a science than a heap of stones is a house." - Henri Poincare

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreSoftware Design > combining binary numbers


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT