Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 779305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T19:54:31+00:00 2026-05-14T19:54:31+00:00

I once saw an article about how to use a specific type of numbering

  • 0

I once saw an article about how to use a specific type of numbering system to manage roles. A user would be assigned a specific role number and depending on a calculation, the number could stand for multiple roles.

Can anybody share this technique with me or share a link? Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T19:54:32+00:00Added an answer on May 14, 2026 at 7:54 pm

    It is a bitmask. It works like this: you assign to each role a progressive number, then when you want to assign one role to a user, you pick the number of that role. If you want to add another role, you just add that role number to the original one. You can add as many roles as you wish. The trick is just how you choose your numbers: they are the powers of 2.

    Here is an example:

    Role: Editor.     Value: 2^0 = 1
    Role: Manager.    Value: 2^1 = 2
    Role: Supervisor. Value: 2^2 = 4
    Role: Admin.      Value: 2^3 = 8
    ...
    

    To give a user the role of Editor, you save 1 to the database,
    To give a user the roles of Editor, Manager and Admin you save 1 + 2 + 8 = 11

    You can see why this works, if you see it as an array of 1 or 0 values.

    |__|__|__|__|__|__|
        16  8  4  2  1 
    

    Each role is a 1 in the corresponding slot. So our 11 case is:

    |__|__|_1|_0|_1|_1|
        16  8  4  2  1 
    

    If you have a bitmask, and you want to know whether the user has a certain role, you use this operation:

    (bitmask & role_value) >= 1

    For example:

    (11 & 8) >= 1? yes, so the user has the admin role
    (11 & 4) >= 1? no, so the user has not the supervisor role

    It is called a bitmask, because what you are doing is to “check whether in a particular position there is a 1”, that is, “apply a mask which will mask (set to 0) all the places, except the one you are searching for):

    11 --> |__|__|_1|_0|_1|_1|
               16  8  4  2  1 
     8 --> |__|__|_1|_0|_0|_0|  (mask)
               16  8  4  2  1 
    AND -> |__|__|_1|_0|_0|_0|  Result: Yes
    

    Hope it helped 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I once saw a text about Jquery stating that in Jquery some properties have
I once saw a question here about whether it is possible to embed fields
I once saw a programming pattern (not design), how to implement a fast copy
I saw something once for wrappers used to do this but it asked for
Once, I saw an example like this: var a, x, y; var r =
I'm sure I saw this happening to me once. In a 64-bit OS with
Once I've, while working with VS, I saw several screens popping up in a
I once have noticied when my Adobe Reader was updating, I saw a small
I saw this article pop-up in my MSDN RSS feed, and after reading through
I more than once saw code of the form: DiceThrower dt = new DiceThrower();

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.