Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<iomanip>
- #include<fstream>
- #include<cmath>
- #include<string>
- using namespace std;
- struct Number { // Structure itself
- unsigned int x[7];
- };
- Number operator + (Number a, Number b) {
- Number temp;
- for (int i = 0; i < 7; i++)
- temp.x[i] = 0;
- for (int i = 6; i >= 0; i--) {
- temp.x[i] += a.x[i] + b.x[i];
- if (i != 0) {
- temp.x[i - 1] += (int)temp.x[i] / pow(10, 9);
- temp.x[i] -= temp.x[i - 1] * pow(10, 9);
- }
- }
- return temp;
- }
- Number operator - (Number a, Number b) {
- Number temp;
- for (int i = 0; i < 7; i++)
- temp.x[i] = 0;
- for (int i = 0; i < 7; i++) {
- int k = 0;
- if (a.x[i] >= b.x[i])
- temp.x[i] += a.x[i] - b.x[i];
- else
- if (i != 0) {
- temp.x[i] += (a.x[i] + pow((int)10, (int)9)) - b.x[i];
- temp.x[i - 1] -= 1;
- }
- }
- return temp;
- }
- bool operator > (Number a, Number b) {
- bool temp;
- int p = 0,
- n = 0;
- for (int i = 0; i < 7; i++) {
- if (a.x[i] > b.x[i])
- p++;
- else
- if (a.x[i] < b.x[i])
- n++;
- if (p == 1 && n == 0) {
- temp = true;
- break;
- }
- else
- if (p == 0 && n == 1) {
- temp = false;
- break;
- }
- else
- if (p == 0 && n == 0)
- temp = false;
- }
- return temp;
- }
- bool operator < (Number a, Number b) {
- bool temp;
- int p = 0,
- n = 0;
- for (int i = 0; i < 7; i++) {
- if (a.x[i] > b.x[i])
- p++;
- else
- if (a.x[i] < b.x[i])
- n++;
- if (p == 0 && n == 1) {
- return true;
- }
- else
- if (p == 1 && n == 0) {
- return false;
- }
- else
- if (p == 0 && n == 0)
- temp = false;
- }
- return temp;
- }
- bool operator == (Number a, Number b) {
- int amount = 0;
- for (int i = 0; i < 7; i++)
- if (a.x[i] == b.x[i])
- amount++;
- if (amount == 7)
- return true;
- else
- return false;
- }
- bool operator != (Number a, Number b) {
- int amount = 0;
- for (int i = 0; i < 7; i++)
- if (a.x[i] == b.x[i])
- amount++;
- if (amount == 7)
- return false;
- else
- return true;
- }
- Number operator & (Number a, Number b) {
- Number temp;
- for (int i = 0; i < 7; i++)
- temp.x[i] = a.x[i] & b.x[i];
- return temp;
- }
- Number operator | (Number a, Number b) {
- Number temp;
- for (int i = 0; i < 7; i++)
- temp.x[i] = a.x[i] | b.x[i];
- return temp;
- }
- Number operator ^ (Number a, Number b) {
- Number temp;
- for (int i = 0; i < 7; i++)
- temp.x[i] = a.x[i] ^ b.x[i];
- return temp;
- }
- Number operator ~ (Number a) {
- for (int i = 0; i < 7; i++)
- a.x[i] = ~a.x[i];
- return a;
- }
- Number operator << (Number a, int x) {
- Number temp;
- for (int i = 0; i < 7; i++)
- temp.x[i] = a.x[i];
- for (int m = 0; m < x; m++) {
- for (int i = 6; i >= 0; i--) {
- temp.x[i] = temp.x[i] << 1;
- if (i != 0)
- temp.x[i - 1] += temp.x[i] >> 31;
- }
- }
- return temp;
- }
- Number operator <<= (Number a, int x) {
- Number temp;
- for (int i = 0; i < 7; i++)
- temp.x[i] = a.x[i];
- for (int m = 0; m < x; m++) {
- for (int i = 6; i >= 0; i--) {
- temp.x[i] = temp.x[i] << 1;
- if (i != 0)
- temp.x[i - 1] += temp.x[i] >> 31;
- else
- temp.x[6] += temp.x[i] >> 31;
- }
- }
- return temp;
- }
- Number operator >> (Number a, int x) {
- Number temp;
- for (int i = 6; i >= 0; i--)
- temp.x[i] = a.x[i];;
- for (int m = 0; m < x; m++) {
- for (int i = 0; i < 7; i++) {
- temp.x[i] = temp.x[i] >> 1;
- if (i != 6)
- temp.x[i + 1] += temp.x[i] << 31;
- }
- }
- return temp;
- }
- Number operator >>= (Number a, int x) {
- Number temp;
- for (int i = 6; i >= 0; i--)
- temp.x[i] = a.x[i];;
- for (int m = 0; m < x; m++) {
- for (int i = 0; i < 7; i++) {
- temp.x[i] = temp.x[i] >> 1;
- if (i != 6)
- temp.x[i + 1] += temp.x[i] << 31;
- else
- temp.x[0] += temp.x[i] << 31;
- }
- }
- return temp;
- }
- void main() {
- Number a[2];
- string A[2]; // Stuffing STRING with numbers
- for (size_t m = 0; m < 2; m++) {
- cout << "Number " << m + 1 << " = ";
- getline(cin, A[m]);
- }
- int len[2] = { A[0].length(), A[1].length() };
- for (size_t m = 0; m < 2; m++) // Zeroing STRUCTs
- for (size_t i = 0; i < 7; i++)
- a[m].x[i] = 0;
- for (size_t m = 0; m < 2; m++) { //Directly stuffing STRUCTs with numbers
- int k1 = 1,
- k2 = 0;
- for (int i = len[m] - 1; i >= 0; i--) {
- a[m].x[7 - k1] += ((int)A[m][i] - 48) * pow(10, k2);
- k2++;
- if (k2 == 9) {
- k1++;
- k2 = 0;
- }
- }
- }
- cout << endl;
- int check;
- for (size_t m = 0; m < 2; m++) { // Printing numbers by 9 numerals
- check = 0;
- cout << "Number " << m + 1 << " = ";
- for (size_t i = 0; i < 7; i++) {
- if (a[m].x[i] != 0)
- check++;
- if (check != 0)
- if (check != 1)
- cout << setw(9) << setfill('0') << a[m].x[i] << " ";
- else
- cout << a[m].x[i] << " ";
- }
- if (check == 0)
- cout << 0;
- cout << endl;
- }
- cout << endl;
- check = 0;
- Number c[2];
- c[0] = a[0] + a[1]; // +
- cout << "a + b = ";
- for (size_t i = 0; i < 7; i++) {
- if (c[0].x[i] != 0)
- check++;
- if (check != 0)
- if (check != 1)
- cout << setw(9) << setfill('0') << c[0].x[i] << " ";
- else
- cout << c[0].x[i] << " ";
- }
- if (check == 0)
- cout << 0;
- cout << endl;
- check = 0;
- c[0] = a[0] - a[1]; // -
- cout << "a - b = ";
- for (size_t i = 0; i < 7; i++) {
- if (c[0].x[i] != 0)
- check++;
- if (check != 0)
- if (check != 1)
- cout << setw(9) << setfill('0') << c[0].x[i] << " ";
- else
- cout << c[0].x[i] << " ";
- }
- if (check == 0)
- cout << 0;
- cout << endl << endl;
- bool C = a[0] > a[1]; // >
- if (C == true)
- cout << "a > b : True" << endl;
- else
- cout << "a > b : False" << endl;
- C = a[0] < a[1]; // <
- if (C == true)
- cout << "a < b : True" << endl;
- else
- cout << "a < b : False" << endl;
- C = a[0] == a[1]; // ==
- if (C == true)
- cout << "a = b : True" << endl;
- else
- cout << "a = b : False" << endl;
- C = a[0] != a[1]; // !=
- if (C == true)
- cout << "a != b : True" << endl << endl;
- else
- cout << "a != b : False" << endl << endl;
- check = 0;
- c[0] = a[0] & a[1]; // &
- cout << "a & b = ";
- for (size_t i = 0; i < 7; i++) {
- if (c[0].x[i] != 0)
- check++;
- if (check != 0)
- if (check != 1)
- cout << setw(9) << setfill('0') << c[0].x[i] << " ";
- else
- cout << c[0].x[i] << " ";
- }
- if (check == 0)
- cout << 0;
- cout << endl;
- check = 0;
- c[0] = a[0] | a[1]; // |
- cout << "a | b = ";
- for (size_t i = 0; i < 7; i++) {
- if (c[0].x[i] != 0)
- check++;
- if (check != 0)
- if (check != 1)
- cout << setw(9) << setfill('0') << c[0].x[i] << " ";
- else
- cout << c[0].x[i] << " ";
- }
- if (check == 0)
- cout << 0;
- cout << endl;
- check = 0;
- c[0] = a[0] ^ a[1]; // ^
- cout << "a ^ b = ";
- for (size_t i = 0; i < 7; i++) {
- if (c[0].x[i] != 0)
- check++;
- if (check != 0)
- if (check != 1)
- cout << setw(9) << setfill('0') << c[0].x[i] << " ";
- else
- cout << c[0].x[i] << " ";
- }
- if (check == 0)
- cout << 0;
- cout << endl;
- c[0] = ~a[0]; // ~
- c[1] = ~a[1];
- for (size_t m = 0; m < 2; m++) {
- if (m == 0)
- cout << "~a = ";
- else
- cout << endl << "~b = ";
- for (size_t i = 0; i < 7; i++)
- if (check != 1)
- cout << setw(9) << setfill('0') << c[m].x[i] << " ";
- else
- cout << c[m].x[i] << " ";
- }
- cout << endl << endl;
- int amount[2];
- cout << "Amount of shifts <- : ";
- cin >> amount[0] >> amount[1];
- c[0] = a[0] << amount[0]; // <<
- c[1] = a[1] << amount[1];
- for (size_t m = 0; m < 2; m++) {
- check = 0;
- if (m == 0)
- cout << "a << " << amount[0] << " = ";
- else
- cout << endl << "b << " << amount[1] << " = ";
- for (size_t i = 0; i < 7; i++) {
- if (c[m].x[i] != 0)
- check++;
- if (check != 0)
- if (check != 1)
- cout << setw(9) << setfill('0') << c[m].x[i] << " ";
- else
- cout << c[m].x[i] << " ";
- }
- if (check == 0)
- cout << 0;
- }
- cout << endl;
- cout << "Amount of shifts -> : "; // >>
- cin >> amount[0] >> amount[1];
- c[0] = a[0] >> amount[0];
- c[1] = a[1] >> amount[1];
- for (size_t m = 0; m < 2; m++) {
- check = 0;
- if (m == 0)
- cout << "a >> " << amount[0] << " = ";
- else
- cout << endl << "b >> " << amount[1] << " = ";
- for (size_t i = 0; i < 7; i++) {
- if (c[m].x[i] != 0)
- check++;
- if (check != 0)
- if (check != 1)
- cout << setw(9) << setfill('0') << c[m].x[i] << " ";
- else
- cout << c[m].x[i] << " ";
- }
- if (check == 0)
- cout << 0;
- }
- cout << endl;
- cout << "Amount of CIRCULAR shifts <- : ";
- cin >> amount[0] >> amount[1];
- c[0] = a[0] <<= amount[0]; // <<=
- c[1] = a[1] <<= amount[1];
- for (size_t m = 0; m < 2; m++) {
- check = 0;
- if (m == 0)
- cout << "a <<= " << amount[0] << " = ";
- else
- cout << endl << "b <<= " << amount[1] << " = ";
- for (size_t i = 0; i < 7; i++) {
- if (c[m].x[i] != 0)
- check++;
- if (check != 0)
- if (check != 1)
- cout << setw(9) << setfill('0') << c[m].x[i] << " ";
- else
- cout << c[m].x[i] << " ";
- }
- if (check == 0)
- cout << 0;
- }
- cout << endl;
- cout << "Amount of CIRCULAR shifts -> : "; // >>=
- cin >> amount[0] >> amount[1];
- c[0] = a[0] >>= amount[0];
- c[1] = a[1] >>= amount[1];
- for (size_t m = 0; m < 2; m++) {
- check = 0;
- if (m == 0)
- cout << "a >>= " << amount[0] << " = ";
- else
- cout << endl << "b >>= " << amount[1] << " = ";
- for (size_t i = 0; i < 7; i++) {
- if (c[m].x[i] != 0)
- check++;
- if (check != 0)
- if (check != 1)
- cout << setw(9) << setfill('0') << c[m].x[i] << " ";
- else
- cout << c[m].x[i] << " ";
- }
- if (check == 0)
- cout << 0;
- }
- cout << endl;
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement