What is the conceptual difference between them? I know bitmap is sort of bitfields in the structs..
struct{
int bit1: 1;
int bit2: 1;
int bit3: 1;
};
so in tht case is bitmask something we define for an enum?
A bitmask is an integer type that is used to "mask" certain bits when performing bitwise operations. For example, the bitmask 0xFFFFFFFF
might be used to mask a 32-bit unsigned value because you want to operate on all bits at once, whereas 0x00000001
would only operate on the very last bit. You often see bitmasks defined as the 'flipped' version and then flipped using ~
.
A bitmap, on the other hand, is a set of variables each mapped to an individual bit. There are many ways of achieving this, your struct is one (common) example of a bitmap.
You might put various masks in an enum to give yourself easier access to them, but it's not strictly necessary to do so.
Bitmap is more of data itself which comprise of bits. One of the example could be say that there are 8 friends in a group and group performs various activities together. Group participation in each activity now can be represented by "bitmap" which comprise of bits (each for one friend). e.g.
Skii - 10110000 <<<<friend 5,6 and 8 will go to Skii
Movie - 10011000 <<< friend 4,5 and 8 will go to movie
College- 11111111 <<<all friends will go to college
Bitmask is more skeleton for bitmap. bitmask will be used to set and get bit values in bitmap.
friend1 - 00000001<<<< bitmask for friend 1
friend2 - 00000010 <<<bitmask for friend 2
friend5 - 00010000
(Note: I found it awkward to address friend0 :) , purist may consider everything as n-1)
Now using bitmap and bitmask we can determine
Skii & friend1 <<<< this would be zero
Movie & friend5 <<< yes
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