Solved

Using powers of two (?) to determine various access levels

Posted on 2008-10-11
2
255 Views
Last Modified: 2012-05-05
I think there is a way to use powers of two or something similar to determine different levels. For instance, I have different access (different parts of my site), that different people should be able to access. I believe that by using division or modulus division there is a way to have a unique number for each situation. For instance, if someone was able to access areas 1, 3, and 4, the numbers would be divisible by a certain number for each, but not others. Can anyone guide me in the right direction? thanks
0
Comment
Question by:bkaneweb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 18

Accepted Solution

by:
Hube02 earned 500 total points
ID: 22695972
I have used a somewhat binary system to determine things like this in the past. For instance, each item is 2 times the last item, so the numeric value of the items run:

1, 2, 4, 8, 16, 31, 64, 128, 256, 1024, etc... (you should recognize this pattern)

Now comes the part where you determine what "BITS" are on and which are off.

Let's call the variable that holds this value "permissions".

So, lets say that the value contained in $permissions is 9. this means that the permission with the value of 1 and the permission with the value of 8 are on.

this line will detect if the "1 BIT is on"

if ($permissions&1)

What it does is this. We do a binary AND of $permissions & 1. If the 1 Bit is on the expression will return an non zero value which evaluates as true. If the 1 Bit is off then 0 is returned and the expression evaluates as false.

The same can be done at any level

if ($permissions&8) will return true (actually 8) if the 4th bit is on and false (0) if it is off.

Hopefully that helps and is at least close to what you are looking for. Let me know if you have any questions.



0
 

Author Closing Comment

by:bkaneweb
ID: 31505381
That worked great...thanks so much for the explanation and example!!!!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question