-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.cpp
More file actions
41 lines (33 loc) · 759 Bytes
/
main.cpp
File metadata and controls
41 lines (33 loc) · 759 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
#include <iostream>
#include <memory>
#include <istream>
#include <ostream>
#include <random>
using namespace std;
#include "Buffer.hpp"
template<typename intType>
string dec2bin(const intType &n){
size_t length = sizeof(intType) * 8;
string res;
for(size_t i = 0; i < length; ++i)
if(n & 1 << (length - i - 1))
res += "1";
else
res += "0";
return res;
}
int main(){
uint32_t size = 10;
Buffer buffer(size);
random_device rd;
for(uint32_t i = 0; i < size; ++i)
buffer.write<uint8_t>(0);
buffer.setBit(true, 8);
buffer.setBit(true, 18);
buffer.setBit(true, 28);
buffer.setBit(true, 38);
buffer.setBit(true, 48);
buffer.setBit(true, 79);
for(uint32_t i = 0; i < size; ++i)
cout << dec2bin<uint8_t>(buffer.get(i)) << endl;
}