Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- #include <chrono>
- using namespace std;
- const int MAX_VALUE = 15;
- class word{
- int values;
- public:
- word(){
- int set = 0;
- for(int i = 0; i <= MAX_VALUE; i++)
- {
- if(rand() % 2 == 1)
- set |= (1 << i);
- }
- this->values=set;
- };
- word(int values){this->values=values;};
- // --- --- ---
- void print_set()
- {
- cout << "{ ";
- for(int i = 0; i <= MAX_VALUE; i++)
- {
- if ((this->values & (1 << i)) != 0) // проверяем установлен ли i-й бит в маске
- cout << hex << i << " "; // выводим элемент в 16-ричной системе исчисления
- }
- cout << '}' << endl;
- }
- // --- --- ---
- word operator && (const word& second) const
- {
- return word{values & second.values };
- }
- // --- --- ---
- word operator || (const word& second) const
- {
- return word{values | second.values};
- }
- // --- --- ---
- word operator - (const word& second) const
- {
- return word{values & ~second.values};
- }
- };
- int main() {
- srand(2);
- word a, b, c, d, e(0);
- cout<<"a:"; a.print_set();
- cout<<"b:"; b.print_set();
- cout<<"c:"; c.print_set();
- cout<<"d:"; d.print_set();
- double result;
- cout << endl << "*Calculating result*" << endl;
- for(int i = 0; i < pow(10, 7); i++)
- {
- auto t1 = chrono::high_resolution_clock::now();
- e = ((a||c)-(b||d));
- auto t2 = chrono::high_resolution_clock::now();
- auto diff = chrono::duration_cast<chrono::duration<double>>(t2 - t1);
- result += diff.count();
- }
- cout << endl << "E: "; e.print_set();
- cout << "time: " << result << " seconds" << endl;
- return 0;
- }
Add Comment
Please, Sign In to add comment