-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbitset.cpp
More file actions
64 lines (42 loc) · 884 Bytes
/
bitset.cpp
File metadata and controls
64 lines (42 loc) · 884 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <iostream>
#include <bitset>
using namespace std;
#define BT_SZ 8
class bitmap {
public:
bitmap(string bufp) {
bitmap_ = bufp;
std::bitset<BT_SZ> bt(bitmap_);
bt_ = bt;
}
std::bitset<BT_SZ> Init() {
std::bitset<BT_SZ> bt(bitmap_);
bt_ = bt;
return bt;
}
bool Any() {
return bt_.any();
}
size_t Count() {
return bt_.count();
}
bool All() {
return bt_.all();
}
bool None() {
return bt_.none();
}
private:
std::bitset<BT_SZ> bt_;
std::string bitmap_;
};
int main(int argc, char *argv[]) {
std::string bt_raw("01111110");
bitmap* obj = new bitmap(bt_raw);
cout << "is Any bit set:" << obj->Any() << endl;
cout << "count of bits set:" << obj->Count() << endl;
cout << "is All bit set:" << obj->All() << endl;
cout << "is None bit set:" << obj->None() << endl;
delete obj;
return 0;
}