Solved

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

Posted on 2008-10-11
2
250 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
2 Comments
 
LVL 18

Accepted Solution

by:
Hube02 earned 500 total points
Comment Utility
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
Comment Utility
That worked great...thanks so much for the explanation and example!!!!
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
copyEndy  challenge 15 55
delphi parse string to params 3 81
Dice Roll Probabilities 3 51
Image decoding from Camera 3 42
If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

743 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now