user1809826
user1809826

Reputation: 27

Limitations to Bitwise Systems

I have just taken some online tutorials on how Bits work. Though I have a couple of questions. I have searched the internet but didn't find what i was looking for. I may have been searching for some incorrect key words.

Lets say i wish to build an option or permission system using bitwise (i think that is the correct terminology). I have the following hestitations:

1) Is it possible to end up with collisions when using & etc?

2) If there is collision opportunities what sort of steps should i take when im designing my permissions? Does the permission numbers change if i have a considerably large set of permissions e.g. over 500?

Hopefully i got my question across correctly, if not please let me know and i will try to rephrase.

EDIT:: Similar Question here which i believe has been answered

User role permissions for different modules using bitwise operators

Upvotes: 1

Views: 1009

Answers (1)

Marc B
Marc B

Reputation: 360752

  1. What kind of collisions?
  2. For 500 different permissions, you'd have to store 500 bits. There's no computers in existence which can directly handle a 500+bit value. With bit systems, you're basically restricted to using what the underlying cpu can provide, e.g. 8, 16, 32, 64-bit sized values. Anything beyond that has to be split into multiple different memory chunks.

e.g.

permission_flags && (1 << 475)

is going to fail on every platform in existence, because once you shift past bit #63, you're past what the cpu can directly support.

Upvotes: 1

Related Questions