Solved

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

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

Independent Software Vendors: 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

Suggested Solutions

The purpose of this article is to demonstrate how we can use conditional statements using Python.
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

738 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