repl.it
@SharkFin/

Complex C++ Testing

C++11

Lambda functions, etc

fork
loading
Files
  • main.cpp
main.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
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
65
66
67
68
69
70
71
72
73
74
75
76
#include <iostream>
#include <string>
#include <cstdlib>
/*void someFunc(auto void(*lf)(int)) {
	for(int i=0;i<2;i++) {
		lf(i);
	}
}*/

std::string rndStr(unsigned int length) {
	std::string str = "";
	for(int i=0;i<length;i++) {
		char chr = rand()%26+'a';
		str += chr;
	}

	return str;
}

int main() {
	srand(time(NULL));
  /*auto hey = [](int n){std::cout << "Hello: " << (char)('a'+n) << std::endl;};
	someFunc(hey);

	// Bit shifting
	int x;
	x = 1 << 0 | 1 << 1;
	std::cout << x << std::endl;

	// Random string
	std::string rndString = rndStr(5);
	std::cout << rndString << std::endl;*/
	std::string rndString;

	// Binary from string
	std::string input = false ? rndString : "tests";
	std::string bin = "";
	for(char character : input) {
		for(int i=8;i>0;i--) {
			bin += std::to_string((character >> i) & 1);
			std::cout << std::to_string((character >> i) & 1);
		}
		//std::cout << ' ';
	}
	std::cout << std::endl;
	//std::cout << bin << std::endl;

	// String from binary string
	std::string binary = bin; // Use binary from above
	std::string str = "";
	char workingByte = 0x00;

	for(int i=0;i<binary.length()/8;i++) {
		for(int l=7;l>=0;l--) {
			//std::cout << l;
			if (binary[i+l] == '1') {
				//workingByte |= 1 << 0;
			}
		}
		workingByte |= 
			(int)binary[i+7] << 8 |
			(int)binary[i+6] << 7 |
		  (int)binary[i+5] << 6 |
			(int)binary[i+4] << 5 |
			(int)binary[i+3] << 4 |
			(int)binary[i+2] << 3 |
			(int)binary[i+1] << 2 |
			(int)binary[i] << 1;
		std::cout << workingByte;
		str += workingByte;
		//workingByte = 0x00;
	}
	std::cout << str << std::endl;

	//return 1;
}
?