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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:39:53+00:00 2026-06-01T22:39:53+00:00

Say I have this: // different things you can do var CAN_EAT = 1,

  • 0

Say I have this:

// different things you can do
var CAN_EAT = 1,
    CAN_SLEEP = 2,
    CAN_PLAY = 4,
    CAN_DANCE = 8,
    CAN_SWIM = 16,
    CAN_RUN = 32,
    CAN_JUMP = 64,
    CAN_FLY = 128,
    CAN_KILL = 256,
    CAN_BE_JESUS = Math.pow(2, 70);

// the permissions that I have
var MY_PERMS = CAN_EAT | CAN_SLEEP | CAN_PLAY | CAN_BE_JESUS;

// can I eat?
if(MY_PERMS & CAN_EAT) alert('You can eat!'); /* RUNS */

// can I sleep?
if(MY_PERMS & CAN_SLEEP) alert('You can sleep!'); /* RUNS */

// can I play?
if(MY_PERMS & CAN_PLAY) alert('You can play!'); /* RUNS */

// can I be jesus?
if(MY_PERMS & CAN_BE_JESUS) alert('You can be jesus!'); /* WONT RUN */

Then if I run it, it will print out that I can eat, sleep and play. It will not print out that I can be jesus, because that number is 2^70. If I make the number 2^31 then it will work (I’m on a 64bit machine but must be running Chrome in 32bit mode when I ran the above example).

I face this problem in PHP all the time as well, when dealing with bitwise operators. Often I can work the scenario I’m in to make it so having a maximum of 31 or 63 things in my list isn’t a big deal, but sometimes I need to have much more than that. Is there any way around this limitation? Bitwise operators are so speedy, and convenient.

  • 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-01T22:39:55+00:00Added an answer on June 1, 2026 at 10:39 pm

    Well, the problem with this is apparently, as you suspected, the width of the integer in javascript. According to this, numbers in js can go up to 2^53, so you can have 53 different bits. According to this, in 64-bit machines, php goes all the way up to 2^63 – 1, so you get 62 bits.
    If you need more, you should re-think your design – could you perhaps divide the flags into 2 (or more) groups, where each group has its own meaning (like food-related actions, other actions, anything else, etc.)?

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

Sidebar

Related Questions

Lets say have this immutable record type: public class Record { public Record(int x,
Say I have this given XML file: <root> <node>x</node> <node>y</node> <node>a</node> </root> And I
Say i have this PHP code: $FooBar = a string; i then need a
Say I have this simple form: class ContactForm(forms.Form): first_name = forms.CharField(required=True) last_name = forms.CharField(required=True)
say I have this $result = mysql_query('SELECT views FROM post ORDER BY views ASC');
Say I have this column returned in a command for Crystal: deposit_no 123 130
Say I have this table: Person table -------------- PersonId Address table ------------ AddressId PersonAddressId
Say I have this table schema. ID AccNo Amount Say I have this data
Say I have this code - public interface ParentInterface1 { public List<? extends ChildInterface1>
Say I have this code: #import <UIKit/UIKit.h> @interface MyView : UIView @end @implementation MyView

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.