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 42897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T15:24:36+00:00 2026-05-10T15:24:36+00:00

I was going to ask a question here about whether or not my design

  • 0

I was going to ask a question here about whether or not my design for some users/roles database tables was acceptable, but after some research I came across this question:

What is the best way to handle multiple permission types?

It sounds like an innovative approach, so instead of a many-to-many relationship users_to_roles table, I have multiple permissions defined as a single decimal (int data type I presume). That means all permissions for a single user are in one row. It probably won’t make sense until you read the other question and answer

I can’t get my brain around this one. Can someone please explain the conversion process? It sounds ‘right’, but I’m just not getting how I convert the roles to a decimal before it goes in the db, and how it gets converted back when it comes out of the db. I’m using Java, but if you stubbed it out, that would be cool as well.

Here is the original answer in the off chance the other question gets deleted:

‘Personally, I sometimes use a flagged enumeration of permissions. This way you can use AND, OR, NOT and XOR bitwise operations on the enumeration’s items.

[Flags] public enum Permission {     VIEWUSERS = 1, // 2^0 // 0000 0001     EDITUSERS = 2, // 2^1 // 0000 0010     VIEWPRODUCTS = 4, // 2^2 // 0000 0100     EDITPRODUCTS = 8, // 2^3 // 0000 1000     VIEWCLIENTS = 16, // 2^4 // 0001 0000     EDITCLIENTS = 32, // 2^5 // 0010 0000     DELETECLIENTS = 64, // 2^6 // 0100 0000 } 

Then, you can combine several permissions using the AND bitwise operator.

For example, if a user can view & edit users, the binary result of the operation is 0000 0011 which converted to decimal is 3. You can then store the permission of one user into a single column of your DataBase (in our case it would be 3).

Inside your application, you just need another bitwise operation (OR) to verify if a user has a particular permission or not.’

  • 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. 2026-05-10T15:24:36+00:00Added an answer on May 10, 2026 at 3:24 pm

    You use bitwise operations. The pseudo-code would be something like:

    bool HasPermission(User user, Permission permission) {     return (user.Permission & permission) != 0; }  void SetPermission(User user, Permission permission) {     user.Permission |= permission; }  void ClearPermission(User user, Permission permission) {     user.Permission &= ~permission; } 

    Permission is the enum type defined in your post, though whatever type it is needs to be based on an integer-like type. The same applies to the User.Permission field.

    If those operators (&, |=, and &=) don’t make sense to you, then read up on bitwise operations (bitwise AND and bitwise OR).

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

Sidebar

Ask A Question

Stats

  • Questions 68k
  • Answers 68k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer I might not have understood your question fully, but using… May 11, 2026 at 12:13 pm
  • added an answer Animate your view so it moves offscreen/shrinks/expands/fades, then do the… May 11, 2026 at 12:13 pm
  • added an answer I'm not sure I understand why you can't use the… May 11, 2026 at 12:13 pm

Related Questions

I was going to ask a question here about whether or not my design
I was going to Ask a Question earlier today when I was presented to
I was going to ask a question about preparing a desktop application to support
If I was going to start an open source project using Python what version
I have a project that I thought was going to be relatively easy, but
I'm new to this SCM, but since SVN is gaining popularity I was going
If I was, for example, going to count activities across many computers and show
I was going through the AWDR book on web development with ruby on rails
I was going through some code and came across a scenario where my combobox
I was going through a few queries I am maintaining, and a programmer had

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.