Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string.h>
- #include <stdlib.h>
- #include <conio.h>
- #include <string>
- #include <Windows.h>
- #include <fstream>
- #include "gnuplot.h"
- using namespace std;
- const short int colordef = 15;
- const short int black = 0;
- double degree(int deg, int number) {
- double res = 0;
- double number1 = (double)number;
- _asm
- {
- push ecx //сохраняем регистры на стеке под наше пользование
- push ebx
- finit //инициализируем сопроцессор
- mov ecx, deg //муваем deg в ecx
- mov ebx, 0 //ebx - флажок (1 если deg < 0)
- fld number1 //кладем в стек сопроцессора number1
- fld1 //кладем в стек сопроцессора 1
- cmp ecx, 0 //сравнение
- jg l //если больше идём в цикл
- je endP //если равно идем в конец программы
- //если мы сюда зашли => deg < 0
- neg ecx //отрицаем ecx (deg)
- mov ebx, 1 //ставим флаг на то, что deg < 0
- l:
- cmp ecx, 0 //если deg 0
- je endP //идем в конец программы
- dec ecx //декриментируем ecx (deg)
- cmp ebx, 0 //проверяем значение флага ( deg < 0 ??? )
- jg divv //если deg < 0 идем в деление divv
- fmul st(0), st(1) //иначе умножаем то, что у нас в стеке сопроцессора и кладем в st(0)
- jmp l //прыгаем на l
- divv :
- fdiv st(0), st(1) //делим то, что у нас в стеке сопроцессора и кладем в st(0)
- jmp l //прыгаем на l
- endP :
- fstp res //забираем из стека сопроцессора и кладем в res
- pop ebx //
- pop ecx
- }
- return res;
- }
- void numberEnter(string& str, int numberSystem, char& sign) {
- char ch = 0;
- while (ch != 13) {
- ch = _getch();
- if (ch == '-') {
- sign *= -1;
- cout << ch;
- }
- else {
- if (numberSystem > 36) {
- if ((ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch < numberSystem + '0' + 7 + 6)) {
- cout << ch;
- str += ch;
- }
- }
- else {
- if (numberSystem > 10) {
- if ((ch >= '0' && ch <= '9') || (ch >= 'A' && ch < numberSystem + '0' + 7)) {
- cout << ch;
- str += ch;
- }
- }
- else {
- if (ch >= '0' && ch < numberSystem + '0') {
- cout << ch;
- str += ch;
- }
- }
- }
- }
- }
- }
- void fractionalNumberEnter(string& str, int numberSystem, char& sign, int& dotPos) {
- char ch = 0;
- int k = 0;
- while (ch != 13) {
- ch = _getch();
- if (ch == '.' && dotPos == -1) {
- dotPos = k;
- cout << ch;
- str += ch;
- k++;
- }
- else {
- if ((ch == '-' && str.length() == 0) || (ch == '-' && str[str.length() - 1] == '-')) {
- sign *= -1;
- cout << ch;
- }
- else {
- if (numberSystem > 36) {
- if ((ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch < numberSystem + '0' + 7 + 6)) {
- cout << ch;
- str += ch;
- }
- }
- else {
- if (numberSystem > 10) {
- if ((ch >= '0' && ch <= '9') || (ch >= 'A' && ch < numberSystem + '0' + 7)) {
- cout << ch;
- str += ch;
- }
- }
- else {
- if (ch >= '0' && ch < numberSystem + '0') {
- cout << ch;
- str += ch;
- }
- }
- }
- k++;
- }
- }
- }
- }
- void charEnter(string& charEnter) {
- char ch = 0;
- while (ch != 13/*return*/) {
- ch = _getch();
- if (ch >= '0' && ch <= '9') {
- cout << ch;
- charEnter += ch;
- }
- if ((charEnter[0] > '2' && charEnter.length() >= 2) || (charEnter.length() == 3))
- break;
- }
- }
- void printAlphabet(int numberSystem) {
- cout << "Admissible characters: ";
- for (int i = 0; i < numberSystem; i++) {
- if (i < 10)
- cout << "\t" << char(i + '0') << "-" << i << " ";
- if (i >= 10 && i < 36)
- cout << "\t" << char(i + '0' + 7) << "-" << i << " ";
- if (i >= 36)
- cout << "\t" << char(i + '0' + 7 + 6) << "-" << i << " ";
- }
- cout << endl;
- }
- void colorChoice(short int& color0, short int& color1, HANDLE hConsole) {
- cout << "Choose colors for bits!\n";
- char ch = '0', choose;
- for (int i = 0; i < 10; i++) {
- if (i == 0)
- SetConsoleTextAttribute(hConsole, (WORD)((15 << 4) | i));
- else
- SetConsoleTextAttribute(hConsole, (WORD)((0 << 4) | i));
- cout << char(254) << char(254) << char(254) << char(254) << char(254) << " - [" << i << "]\n";
- }
- for (int i = 10; i < 16; i++) {
- SetConsoleTextAttribute(hConsole, (WORD)((0 << 4) | i));
- cout << char(254) << char(254) << char(254) << char(254) << char(254) << " - [" << char(ch + i + 7) << "]\n";
- }
- SetConsoleTextAttribute(hConsole, (WORD)((0 << 4) | colordef));
- cout << "Choose color for zeros: ";
- do {
- choose = _getch();
- } while (!((choose >= '0' && choose <= '9') || (choose >= 'A' && choose <= 'F')));
- if (choose > '9') {
- color0 = choose - '0' - 7;
- }
- else {
- color0 = choose - '0';
- }
- choose = 0;
- if (color0 != 0)
- SetConsoleTextAttribute(hConsole, (WORD)((0 << 4) | color0));
- else
- SetConsoleTextAttribute(hConsole, (WORD)((colordef << 4) | color0));
- cout << 0 << endl;
- SetConsoleTextAttribute(hConsole, (WORD)((0 << 4) | colordef));
- cout << "Choose color for units: ";
- do {
- choose = _getch();
- } while (!((choose >= '0' && choose <= '9') || (choose >= 'A' && choose <= 'F')));
- if (choose > '9') {
- color1 = choose - 7 - '0';
- }
- else {
- color1 = choose - '0';
- }
- if (color1 != 0)
- SetConsoleTextAttribute(hConsole, (WORD)((0 << 4) | color1));
- else
- SetConsoleTextAttribute(hConsole, (WORD)((colordef << 4) | color1));
- cout << 1 << endl;
- SetConsoleTextAttribute(hConsole, (WORD)((0 << 4) | colordef));
- }
- void print_graph(int size) {
- Gnuplot plot;
- string str = "set xrange [-0.25:";
- str += to_string(size - 1) + ".25]";
- plot(str);
- plot("set yrange [-0.25:1.25]");
- plot("plot \'E:\\VisualStudio\\projects\\oevm1\\oevm1\\data.txt\' lt 7 lc 22 with linespoints");
- cout << endl;
- system("pause");
- }
- void bit_print(char* arr, int size, HANDLE hConsole, short int color0, short int color1, bool changing = false, int index = -1, bool graph = false) {
- ofstream file("data.txt");
- for (int i = size - 1; i >= 0; i--) {
- for (int j = 0; j < sizeof(char) * 8; j++) {
- int k = (i) * sizeof(char) * 8 + (8 - j - 1);
- file << k << " ";
- if (arr[i] & 128) {
- if (k < 100)
- file << 1;
- if (changing && k == index) {
- SetConsoleTextAttribute(hConsole, (WORD)((15 << 4) | black));
- cout << "1";
- }
- else {
- SetConsoleTextAttribute(hConsole, (WORD)((0 << 4) | color1));
- cout << "1";
- }
- }
- else {
- file << 0;
- if (changing && k == index) {
- SetConsoleTextAttribute(hConsole, (WORD)((15 << 4) | black));
- cout << "0";
- }
- else {
- SetConsoleTextAttribute(hConsole, (WORD)((0 << 4) | color0));
- cout << 0;
- }
- }
- arr[i] <<= 1;
- if (k > 0)
- file << "\n";
- }
- }
- SetConsoleTextAttribute(hConsole, (WORD)((0 << 4) | colordef));
- file.close();
- if (graph)
- print_graph(size * 8);
- }
- void bit_print(char ch, short int color0, short int color1, HANDLE hConsole, bool changing = false, int index = -1, bool graph = false) {
- ofstream file("data.txt");
- for (int i = 0; i < sizeof(char) * 8; i++) {
- file << 7 - i << " ";
- if (ch & 128) {
- file << 1;
- if (changing && (8 - i - 1) == index) {
- SetConsoleTextAttribute(hConsole, (WORD)((15 << 4) | black));
- cout << "1";
- }
- else {
- SetConsoleTextAttribute(hConsole, (WORD)((0 << 4) | color1));
- cout << "1";
- }
- }
- else {
- file << 0;
- if (changing && (8 - i - 1) == index) {
- SetConsoleTextAttribute(hConsole, (WORD)((15 << 4) | black));
- cout << "0";
- }
- else {
- SetConsoleTextAttribute(hConsole, (WORD)((0 << 4) | color0));
- cout << 0;
- }
- }
- ch <<= 1;
- file << "\n";
- }
- SetConsoleTextAttribute(hConsole, (WORD)((0 << 4) | colordef));
- file.close();
- if (graph)
- print_graph(8);
- }
- void bitChange(char& number, HANDLE hConsole, short int color0, short int color1) {
- cout << "Enter index of the 1st bit: ";
- int index, n;
- char temp;
- cin >> index;
- if (index >= sizeof(char) * 8 || index < 0)
- return;
- cout << "Enter number of bits that u wanna change: ";
- cin >> n;
- if (n + index > sizeof(char) * 8) {
- cout << "ERROR: number + index is bigger than size of data type\n";
- return;
- }
- cout << "\nNOTICE!!!\n\nYou will get a cursor for indexes that you will be able to change, just press 1 or 0 and you will change it.\n\n";
- system("pause");
- system("cls");
- bit_print(number, color0, color1, hConsole, true, index);
- char ch = 0;
- cout << "Enter bits: ";
- int i = index;
- while (i < n && ch != 13) {
- ch = _getch();
- switch (ch) {
- case '1':
- SetConsoleTextAttribute(hConsole, (WORD)((0 << 4) | color1));
- temp = 1;
- temp <<= i;
- number = number | temp;
- system("cls");
- bit_print(number, color0, color1, hConsole, true, i + 1);
- break;
- case '0':
- SetConsoleTextAttribute(hConsole, (WORD)((0 << 4) | color0));
- temp = -1;
- temp -= 1 << i;
- number = number & temp;
- system("cls");
- bit_print(number, color0, color1, hConsole, true, i + 1);
- break;
- default:
- i--;
- }
- i++;
- }
- SetConsoleTextAttribute(hConsole, (WORD)((0 << 4) | colordef));
- cout << endl;
- }
- void bitChange(int& number, HANDLE hConsole, short int color0, short int color1) {
- union {
- int _number;
- char bytes[sizeof(int)];
- };
- _number = number;
- cout << "Enter index of the 1st bit: ";
- int index, temp, n;
- cin >> index;
- if (index >= sizeof(int) * 8 || index < 0)
- return;
- cout << "Enter number of bits that u wanna change: ";
- cin >> n;
- if (n + index > sizeof(float) * 8) {
- cout << "ERROR: number + index is bigger than size of data type\n";
- return;
- }
- cout << "\nNOTICE!!!\n\nYou will get a cursor for indexes that you will be able to change, just press 1 or 0 and you will change it.\n\n";
- system("pause");
- system("cls");
- bit_print(bytes, sizeof(int), hConsole, color0, color1, true, index);
- char ch = 0;
- int i = index;
- n = n + index;
- while (i < n && ch != 13) {
- ch = _getch();
- switch (ch) {
- case '1':
- SetConsoleTextAttribute(hConsole, (WORD)((0 << 4) | color1));
- temp = 1;
- temp <<= i;
- number = number | temp;
- _number = number;
- system("cls");
- bit_print(bytes, sizeof(int), hConsole, color0, color1, true, i + 1);
- break;
- case '0':
- SetConsoleTextAttribute(hConsole, (WORD)((0 << 4) | color0));
- temp = -1;
- temp -= 1 << i;
- number = number & temp;
- _number = number;
- system("cls");
- bit_print(bytes, sizeof(int), hConsole, color0, color1, true, i + 1);
- break;
- default:
- i--;
- }
- i++;
- }
- SetConsoleTextAttribute(hConsole, (WORD)((0 << 4) | colordef));
- cout << endl;
- }
- void bitChange(char* arr, int size, HANDLE hConsole, short int color0, short int color1) {
- cout << "Enter index of the 1st bit: ";
- int index, n;
- char temp;
- char temparr[sizeof(double)];
- for (int i = 0; i < sizeof(double); ++i) {
- temparr[i] = arr[i];
- }
- cin >> index;
- if (index >= sizeof(char) * 8 * size || index < 0)
- return;
- cout << "Enter number of bits that u wanna change: ";
- cin >> n;
- if (n + index > sizeof(char) * 8 * size) {
- cout << "ERROR: number + index is bigger than size of data type\n";
- return;
- }
- cout << "\nNOTICE!!!\n\nYou will get a cursor for indexes that you will be able to change, just press 1 or 0 and you will change it.\n\n";
- system("pause");
- system("cls");
- bit_print(temparr, size, hConsole, color0, color1, true, index);
- for (int i = 0; i < sizeof(double); ++i) {
- temparr[i] = arr[i];
- }
- char ch = 0;
- int i = index;
- while (i < n + index && ch != 13) {
- ch = _getch();
- switch (ch) {
- case '1':
- SetConsoleTextAttribute(hConsole, (WORD)((0 << 4) | color1));
- temp = 1;
- temp <<= i % 8;
- arr[i / 8] |= temp;
- temparr[i / 8] = arr[i / 8];
- system("cls");
- bit_print(temparr, size, hConsole, color0, color1, true, i + 1);
- for (int i = 0; i < sizeof(double); ++i) {
- temparr[i] = arr[i];
- }
- break;
- case '0':
- SetConsoleTextAttribute(hConsole, (WORD)((0 << 4) | color0));
- temp = -1;
- temp -= 1 << i % 8;
- arr[i / 8] &= temp;
- temparr[i / 8] = arr[i / 8];
- system("cls");
- bit_print(temparr, size, hConsole, color0, color1, true, i + 1);
- for (int i = 0; i < sizeof(double); ++i) {
- temparr[i] = arr[i];
- }
- break;
- default:
- i--;
- }
- i++;
- }
- SetConsoleTextAttribute(hConsole, (WORD)((0 << 4) | colordef));
- cout << endl;
- }
- void bitChange(INT64& number, HANDLE hConsole, short int color0, short int color1) {
- union {
- INT64 _number;
- char bytes[sizeof(long long)];
- };
- _number = number;
- cout << "Enter index of the 1st bit: ";
- int i, n;
- INT64 temp;
- cin >> i;
- if (i > sizeof(INT64) * 8 || i < 0)
- return;
- cout << "Enter number of bits that u wanna change: ";
- cin >> n;
- if (n + i > sizeof(INT64) * 8) {
- cout << "ERROR: number + index is bigger than size of data type\n";
- return;
- }
- cout << "\nNOTICE!!!\n\nYou will get a cursor for indexes that you will be able to change, just press 1 or 0 and you will change it.\n\n";
- system("pause");
- system("cls");
- bit_print(bytes, sizeof(INT64), hConsole, color0, color1, true, i);
- if (i >= sizeof(INT64) * 8 || i < 0)
- return;
- char ch = 0;
- n = n + i;
- while (i < n && ch != 13) {
- ch = _getch();
- switch (ch) {
- case '1':
- SetConsoleTextAttribute(hConsole, (WORD)((0 << 4) | color1));
- temp = 1;
- temp <<= i;
- number = number | temp;
- _number = number;
- system("cls");
- bit_print(bytes, sizeof(INT64), hConsole, color0, color1, true, i + 1);
- break;
- case '0':
- SetConsoleTextAttribute(hConsole, (WORD)((0 << 4) | color0));
- temp = -1;
- temp -= 1 << i;
- number = number & temp;
- _number = number;
- system("cls");
- bit_print(bytes, sizeof(INT64), hConsole, color0, color1, true, i + 1);
- break;
- default:
- i--;
- }
- i++;
- }
- SetConsoleTextAttribute(hConsole, (WORD)((0 << 4) | colordef));
- cout << endl;
- }
- void int_processing(int numberSystem, HANDLE hConsole) {
- union {
- int number;
- char bytes[sizeof(int)];
- };
- number = 0;
- char sign = 1;
- string intEnter = "";
- system("cls");
- cout << "INT " << numberSystem << " system\n";
- printAlphabet(numberSystem);
- cout << "Enter number: ";
- numberEnter(intEnter, numberSystem, sign);
- for (int i = 0; i < intEnter.length(); i++) {
- if (intEnter[i] >= 'a') {
- number += (intEnter[i] - '0' - 7 - 6) * degree(intEnter.length() - i - 1, numberSystem);
- }
- else {
- if (intEnter[i] >= 'A') {
- number += (intEnter[i] - '0' - 7) * degree(intEnter.length() - i - 1, numberSystem);
- }
- else {
- number += (intEnter[i] - '0') * degree(intEnter.length() - i - 1, numberSystem);
- }
- }
- }
- number *= sign;
- cout << endl;
- short int color0, color1;
- colorChoice(color0, color1, hConsole);
- cout << "decimal notation: " << number << endl;
- int temp;
- temp = number;
- cout << "binary notation: ";
- bit_print(bytes, sizeof(int), hConsole, color0, color1, false, -1, true);
- cout << endl;
- char exitcode;
- do {
- cout << "Dou you want to change some bits?\n[y] - yes\n[n] - no";
- char ch = 0;
- do {
- ch = _getch();
- } while (ch != 'y' && ch != 'n');
- cout << endl;
- if (ch == 'y') {
- bitChange(temp, hConsole, color0, color1);
- number = temp;
- cout << "changed demical notation: " << number << endl;
- cout << "changed binary notation: ";
- bit_print(bytes, sizeof(int), hConsole, color0, color1, false, -1, true);
- cout << endl;
- }
- cout << "Press ECS to exit, RETURN to continue...\n";
- do {
- exitcode = _getch();
- } while (exitcode != 27 && exitcode != 13);
- } while (exitcode != 27);
- system("cls");
- }
- void float_proccesing(int numberSystem, HANDLE hConsole) {
- union {
- float number;
- int inumber;
- char bytes[sizeof(float)];
- };
- number = 0;
- char sign2 = 1;
- int dotPos = -1;
- string floatEnter = "";
- system("cls");
- cout << "FLOAT " << numberSystem << " system\n";
- printAlphabet(numberSystem);
- cout << "Enter number: ";
- fractionalNumberEnter(floatEnter, numberSystem, sign2, dotPos);
- if (dotPos != -1) {
- for (int i = 0; i < dotPos; i++) {
- if (floatEnter[i] - '0' < 10)
- number += (floatEnter[i] - '0') * degree(dotPos - i - 1, numberSystem);
- else {
- if (floatEnter[i] <= 'Z') {
- number += (floatEnter[i] - '0' - 7 /*number that deletes the difference between the character A and number 10*/) * degree(dotPos - i - 1, numberSystem);
- }
- else {
- number += (floatEnter[i] - '0' - 7 - 6 /*number that deletes the difference between the character a and 10*/) * degree(dotPos - i - 1, numberSystem);
- }
- }
- }
- for (int i = dotPos + 1; i < floatEnter.length(); i++) {
- if (floatEnter[i] - '0' < 10)
- number += (floatEnter[i] - '0') * degree(dotPos - i, numberSystem);
- else {
- if (floatEnter[i] <= 'Z') {
- number += (floatEnter[i] - '0' - 7 /*number that deletes the difference between the character A and number 10*/) * degree(dotPos - i, numberSystem);
- }
- else {
- number += (floatEnter[i] - '0' - 7 - 6 /*number that deletes the difference between the character a and number 10*/) * degree(dotPos - i, numberSystem);
- }
- }
- }
- }
- else {
- for (int i = 0; i < floatEnter.length(); i++) {
- if (floatEnter[i] - '0' < 10) {
- number += (floatEnter[i] - '0') * degree(floatEnter.length() - i - 1, numberSystem);
- }
- else {
- number += (floatEnter[i] - '0' - 7 /*number that deletes the difference between the character A and number 10*/) * degree(floatEnter.length() - i - 1, numberSystem);
- }
- }
- }
- number *= sign2;
- cout << endl;
- short int color0, color1;
- colorChoice(color0, color1, hConsole);
- cout << "decimal notation: " << fixed << number << endl;
- int temp;
- temp = inumber;
- cout << "binary notation: ";
- bit_print(bytes, sizeof(float), hConsole, color0, color1, false, -1, true);
- cout << endl;
- char exitcode;
- do {
- cout << "Dou you want to change some bits?\n[y] - yes\n[n] - no";
- char chr;
- chr = 0;
- do {
- chr = _getch();
- } while (chr != 'y' && chr != 'n');
- cout << endl;
- if (chr == 'y') {
- bitChange(temp, hConsole, color0, color1);
- inumber = temp;
- cout.unsetf(ios::fixed);
- cout << "changed demical notation: " << number << endl;
- cout << "changed binary notation: ";
- bit_print(bytes, sizeof(float), hConsole, color0, color1, false, -1, true);
- cout << endl;
- }
- cout << "Press ESC to exit, RETURN to continue...\n";
- do {
- exitcode = _getch();
- } while (exitcode != 27 && exitcode != 13);
- } while (exitcode != 27);
- system("cls");
- }
- void double_proccesing(int numberSystem, HANDLE hConsole) {
- union {
- double number;
- char bytes[sizeof(double)];
- };
- number = 0;
- char sign3 = 1;
- int dotPos2 = -1;
- string doubleEnter = "";
- system("cls");
- cout << "DOUBLE " << numberSystem << " system\n";
- printAlphabet(numberSystem);
- cout << "Enter number: ";
- fractionalNumberEnter(doubleEnter, numberSystem, sign3, dotPos2);
- if (dotPos2 != -1) {
- for (int i = 0; i < dotPos2; i++) {
- if (doubleEnter[i] - '0' < 10)
- number += (doubleEnter[i] - '0') * degree(dotPos2 - i - 1, numberSystem);
- else {
- if (doubleEnter[i] <= 'Z') {
- number += (doubleEnter[i] - '0' - 7 /*number that deletes the difference between the character A and number 10*/) * degree(dotPos2 - i - 1, numberSystem);
- }
- else {
- number += (doubleEnter[i] - '0' - 7 - 6 /*number that deletes the difference between the character a and 10*/) * degree(dotPos2 - i - 1, numberSystem);
- }
- }
- }
- for (int i = dotPos2 + 1; i < doubleEnter.length(); i++) {
- if (doubleEnter[i] - '0' < 10)
- number += (doubleEnter[i] - '0') * degree(dotPos2 - i, numberSystem);
- else {
- if (doubleEnter[i] <= 'Z') {
- number += (doubleEnter[i] - '0' - 7 /*number that deletes the difference between the character A and number 10*/) * degree(dotPos2 - i, numberSystem);
- }
- else {
- number += (doubleEnter[i] - '0' - 7 - 6 /*number that deletes the difference between the character a and number 10*/) * degree(dotPos2 - i, numberSystem);
- }
- }
- }
- }
- else {
- for (int i = 0; i < doubleEnter.length(); i++) {
- if (doubleEnter[i] - '0' < 10) {
- number += (doubleEnter[i] - '0') * degree(doubleEnter.length() - i - 1, numberSystem);
- }
- else {
- if (doubleEnter[i] <= 'Z') {
- number += (doubleEnter[i] - '0' - 7 /*number that deletes the difference between the character A and number 10*/) * degree(doubleEnter.length() - i - 1, numberSystem);
- }
- else {
- number += (doubleEnter[i] - '0' - 7 - 6 /*number that deletes the difference between the character A and number 10*/) * degree(doubleEnter.length() - i - 1, numberSystem);
- }
- }
- }
- }
- number *= sign3;
- cout << endl;
- short int color0, color1;
- colorChoice(color0, color1, hConsole);
- cout << "decimal notation: " << fixed << number << endl;
- char temp[sizeof(double)];
- for (int i = 0; i < sizeof(double); ++i) {
- temp[i] = bytes[i];
- }
- cout << "binary notation: ";
- bit_print(bytes, sizeof(double), hConsole, color0, color1, false, -1, true);
- cout << endl;
- char exitcode;
- do {
- cout << "Dou you want to change some bits?\n[y] - yes\n[n] - no";
- char c;
- c = 0;
- do {
- c = _getch();
- } while (c != 'y' && c != 'n');
- cout << endl;
- if (c == 'y') {
- bitChange(temp, sizeof(double), hConsole, color0, color1);
- for (int i = 0; i < sizeof(double); ++i) {
- bytes[i] = temp[i];
- }
- cout.unsetf(ios::fixed);
- cout << "changed demical notation: " << number << endl;
- cout << "changed binary notation: ";
- bit_print(bytes, sizeof(double), hConsole, color0, color1, false, -1, true);
- cout << endl;
- }
- cout << "Press ESC to exit, RETURN to continue...\n";
- do {
- exitcode = _getch();
- } while (exitcode != 27 && exitcode != 13);
- } while (exitcode != 27);
- system("cls");
- }
- void char_proccesing(HANDLE hConsole) {
- system("cls");
- cout << "CHAR\n";
- char task = 0, character = 0;
- string charString = "";
- do {
- cout << "[1] - character itself\n" << "[2] - code of character";
- task = _getch();
- if (task != '1' && task != '2') {
- system("cls");
- cout << "ERROR: Wrong enter!\n";
- }
- } while (task != '1' && task != '2');
- if (task == '1') {
- cout << "\nEnter a character: ";
- character = _getch();
- cout << character << endl;
- cout << "Code: " << int(character) << endl;
- }
- else {
- cout << "\nEnter code of character: ";
- charEnter(charString);
- for (int i = 0; i < charString.length(); i++) {
- character += (charString[i] - '0') * degree(charString.length() - i - 1, 10);
- }
- cout << "\nCharacter: " << character << endl;
- }
- short int color0, color1;
- colorChoice(color0, color1, hConsole);
- char temp = character;
- cout << "binary notation: ";
- bit_print(character, color0, color1, hConsole, false, -1, true);
- cout << endl;
- char exitcode;
- do {
- cout << "Dou you want to change some bits?\n[y] - yes\n[n] - no";
- char c;
- c = 0;
- do {
- c = _getch();
- } while (c != 'y' && c != 'n');
- cout << endl;
- if (c == 'y') {
- bitChange(temp, hConsole, color0, color1);
- character = temp;
- cout << "changed demical notation: " << int(character) << endl;
- cout << "changed character itself: " << character << endl;
- cout << "changed binary notation: ";
- bit_print(character, color0, color1, hConsole, false, -1, true);
- cout << endl;
- }
- cout << "Press ESC to exit, RETURN to continue...\n";
- do {
- exitcode = _getch();
- } while (exitcode != 27 && exitcode != 13);
- } while (exitcode != 27);
- system("cls");
- cout << "Press ECS to exit...";
- system("cls");
- }
- void bool_proccesing(HANDLE hConsole) {
- union {
- bool flag;
- char help;
- };
- system("cls");
- cout << "BOOL\n";
- cout << "Enter smt: ";
- help = _getch();
- cout << help;
- if (help == '0')
- flag = 0;
- else
- flag = 1;
- cout << endl;
- short int color0, color1;
- colorChoice(color0, color1, hConsole);
- cout << int(&flag) << " " << int(&help) << endl;
- cout << "You entered: " << boolalpha << flag << endl;
- cout << "binary notation: ";
- bit_print(help, color0, color1, hConsole, false, -1, true);
- cout << endl;
- cout << "Press ECS to exit...";
- char exitcode;
- do {
- exitcode = _getch();
- } while (exitcode != 27);
- system("cls");
- }
- void numberSystem_proccesing(int& numberSystem) {
- char ch = 0;
- string numberSystemEnter = "";
- do {
- cout << "Enter number system (2-62): ";
- while (numberSystemEnter.length() < 2 && ch != 13/*return*/) {
- ch = _getch();
- if (ch >= '0' && ch <= '9') {
- if (!(ch == '0' && numberSystemEnter.length() == 0)) {
- cout << ch;
- numberSystemEnter += ch;
- }
- }
- if (numberSystemEnter.length() == 1 && numberSystemEnter[0] > '6') {
- break;
- }
- }
- for (int i = 0; i < numberSystemEnter.length(); i++) {
- numberSystem += (numberSystemEnter[i] - '0') * degree(numberSystemEnter.length() - i - 1, 10);
- }
- if (numberSystem > 62 || numberSystem < 2) {
- system("cls");
- cout << "ERROR: Wrong enter!" << endl;
- ch = 0;
- numberSystem = 0;
- numberSystemEnter = "";
- }
- } while (numberSystem < 2 || numberSystem > 62);
- }
- int main()
- {
- HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
- Gnuplot plot;
- char dataType;
- do {
- int numberSystem = 0;
- cout << "Enter data type\n" << "[1] - int\n" << "[2] - float\n"
- << "[3] - double\n" << "[4] - char\n" << "[5] - bool\n" << "[ESC] - exit\n";
- dataType = _getch();
- if (dataType == '1' || dataType == '2' || dataType == '3') {
- system("cls");
- numberSystem_proccesing(numberSystem);
- }
- switch (dataType) {
- case '1' /*int*/:
- int_processing(numberSystem, hConsole);
- break;
- case '2' /*float*/:
- float_proccesing(numberSystem, hConsole);
- break;
- case '3' /*double*/:
- double_proccesing(numberSystem, hConsole);
- break;
- case '4' /*char*/:
- char_proccesing(hConsole);
- break;
- case '5'/*bool*/:
- bool_proccesing(hConsole);
- break;
- default:
- system("cls");
- cout << "ERROR: Wrong enter!\n";
- }
- } while (dataType != 27 /*esc*/);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement