I always get confused when I am about to use a bit map to store multiple flags. For example, if there are 10 possible properties for an object (all Yes or No), I use an unsigned int and the first 10 bits (from LSB) based on the properties. Now how to set and unset a particular bit and also how to check if a bit is set or not?
If I want to unset the 5th bit, I use: bitand (flag, 2^5 - 1)
But I am not clear on what to use to check if 5th bit is set or not.
Bitmap indexes are widely used in data warehousing applications, which have large amounts of data and ad hoc queries but a low level of concurrent transactions. For such applications, bitmap indexing provides: Reduced response time for large classes of ad hoc queries.
A bitmap index is a special kind of database index that uses bitmaps. Bitmap indexes have traditionally been considered to work well for low-cardinality columns, which have a modest number of distinct values, either absolutely, or relative to the number of records that contain the data.
Bitmap indexes store the bitmaps in a compressed way. If the number of distinct key values is small, bitmap indexes compress better and the space saving benefit compared to a B-tree index becomes even better. Bitmap indexes are most effective for queries that contain multiple conditions in the WHERE clause.
Oracle bitmap indexes are very different from standard b-tree indexes. In bitmap structures, a two-dimensional array is created with one column for every row in the table being indexed. Each column represents a distinct value within the bitmapped index.
check if the nth bit is set:
(flags & (1 << n)) != 0
set the nth bit:
flags |= (1 << n)
clear the nth bit:
flags &= ~(1 << n)
toggle the nth bit:
flags ^= (1 << n)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With