Solved

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

Posted on 2008-10-11
2
251 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
java  and programming certification ? 4 86
STDEVP in SQL 2 58
Beginner to Unreal Engine 4 5 61
Advice on Xojo as a development tool over VB. 4 39
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

895 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