Solved

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

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The purpose of this article is to demonstrate how we can use conditional statements using Python.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

792 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