Блог пользователя manvscode

Автор manvscode, история, 7 лет назад, По-английски

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?

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

»
7 лет назад, # |
  Проголосовать: нравится +5 Проголосовать: не нравится

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.