forked from jancarlsson/snarkfront
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPowersOf2.cpp
39 lines (27 loc) · 870 Bytes
/
PowersOf2.cpp
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
#include "PowersOf2.hpp"
using namespace std;
namespace snarkfront {
size_t sizeBits(const bool& dummy) { return 1; }
size_t sizeBits(const uint32_t& dummy) { return 32; }
size_t sizeBits(const uint64_t& dummy) { return 64; }
vector<int> valueBits(const bool& a) { return vector<int>(1, a); }
template <typename UINT_N>
vector<int> valueBits_internal(const UINT_N& a) {
vector<int> v;
v.reserve(sizeBits(a));
UINT_N b = a;
for (size_t i = 0; i < sizeBits(b); ++i) {
v.push_back(b & 0x1);
b >>= 1;
}
return v;
}
vector<int> valueBits(const uint32_t& a) { return valueBits_internal(a); }
vector<int> valueBits(const uint64_t& a) { return valueBits_internal(a); }
size_t countBits(const vector<int>& v) {
size_t count = 0;
for (const auto& b : v)
count += b;
return count;
}
} // namespace snarkfront