manvscode's blog

By manvscode, history, 7 years ago, In English

I found on many books regarding bitmasks and found out it is great way of representing selections,status, sets etc. But everywhere they have used an integer or long long int to define a bitmask. But that has a max capacity of 64/128 bits. How to represent more items with bits?

  • Vote: I like it
  • 0
  • Vote: I do not like it

»
7 years ago, # |
  Vote: I like it +5 Vote: I do not like it

Look for bitset data structure in different programming languages.

Or simple use array of integers required length. For example if you have array a of 64-bits numbers then you can working with i-th bit something like this:

a[i>>6] & (1ll << (i&63)) - to check if bit is set, 
a[i>>6] | (1ll << (i&63)) - to set bit, 
a[i>>6] ^ (1ll << (i&63)) - to flip bit.