-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbitstreamManipulation.h
More file actions
42 lines (34 loc) · 1.19 KB
/
bitstreamManipulation.h
File metadata and controls
42 lines (34 loc) · 1.19 KB
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
// returns how many bits in a vector of bits
template <size_t N>
int sizeOfBitstream(const std::vector<std::bitset<N>>& bits){
return bits.size() * N;
}
// Loops through every chunk of bits in a vector of bits and prints them out separated by a ' '
template <size_t N>
void logBitStream(std::vector<std::bitset<N>>& bits){
for (std::bitset<N> someBits : bits){
std::cout << someBits << ' ';
}
}
// rotates all bits left by a certain amount for any size bitset
template <size_t N>
std::bitset<N> rotateLeft(const std::bitset<N>& bits, int rotateAmount) {
std::bitset<N> rotatedBits = bits;
for (int i = 0; i < rotateAmount % N; i++) {
bool temp = rotatedBits[N - 1];
rotatedBits <<= 1;
rotatedBits[0] = temp;
}
return rotatedBits;
}
// rotate all bits right by a certain amount
template <size_t N>
std::bitset<N> rotateRight(const std::bitset<N>& bits, int rotateAmount) {
std::bitset<N> rotatedBits = bits;
for (int i = 0; i < rotateAmount % N; i++) {
bool temp = rotatedBits[0];
rotatedBits >>= 1;
rotatedBits[rotatedBits.size() - 1] = temp;
}
return rotatedBits;
}