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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:46:52+00:00 2026-06-11T23:46:52+00:00

I am using bitwise operations in order to represent many access control flags within

  • 0

I am using bitwise operations in order to represent many access control flags within one integer.

ADMIN_ACCESS = 1;
EDIT_ACCOUNT_ACCESS = 2;
EDIT_ORDER_ACCESS = 4;

var myAccess = 3; // ie: ( ADMIN_ACCESS | EDIT_ACCOUNT_ACCESS )

if ( myAccess & EDIT_ACCOUNT_ACCESS ) { // check for correct access
   // allow for editing of account

}

Most of this is occurring on the PHP side of my project. There is one piece however where Javascript is used to join several access flags using | when saving someone’s access level. This works fine to a point. I have found that once an integer (flag) gets too large (> 32bit), it no longer works correctly with bitwise operators in Javascript. For instance:

alert( 4294967296 | 1 ); // equals 1, but should equal 4294967297

I am trying to find a workaround for this so that I do not have to limit my number of access control flags to 32. Each access control flag is two times the previous control flag so that each control flag will not interfere with other control flags.

dec(4) = bin(100)
dec(8) = bin(1000)
dec(16) = bin(10000)

I have noticed that when adding two of these flags together with a simple +, it seems to come out with the same answer as a bitwise or operation, but am having trouble wrapping my head around whether this is a simple substitution, or if there might be problems with doing this. Can anyone comment on the validity of this workaround? Example:

(4294967296 | 262144 | 524288) == (4294967296 + 262144 + 524288)
  • 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-06-11T23:46:53+00:00Added an answer on June 11, 2026 at 11:46 pm

    Simply adding the flags will work provided you know for sure that each flag is a power of two, and that you don’t go past 52 bits long (due to the amount a Double-precision float can hold, since that’s what JS uses for numbers).

    If, for whatever reason, you need more than 52 flags, I would suggest grouping the flags into categories.

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

Sidebar

Related Questions

Is using an integer flag and bitwise operations an effective way of reducing the
I have to convert a decimal number to octal and hexadecimal using bitwise operations.
In Java, is it possible to clear a bit using bitwise operations?
I am trying to use bitwise operations when quering the DB using a CDbCriteria
For a particular application using bitwise masks to store a value, I'd like to
Possible Duplicate: Using a bitwise & inside an if statement I have the following
How can I obtain the value of INT_MAX using only the bitwise operators, in
Possible Duplicate: Efficient bitwise operations for counting bits or find the right|left most ones
I'm messing around with bitwise operations and wanted to implement the simple logic puzzle
I constantly meet people using bitwise operators to do quick, easy and elegant things.

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.