Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 26.19 KB | None | 0 0
  1. #include <iostream>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include <conio.h>
  5. #include <string>
  6. #include <Windows.h>
  7. #include <fstream>
  8. #include "gnuplot.h"
  9. using namespace std;
  10.  
  11. const short int colordef = 15;
  12. const short int black = 0;
  13.  
  14. double degree(int deg, int number) {
  15. double res = 0;
  16. double number1 = (double)number;
  17.  
  18. _asm
  19. {
  20. push ecx //сохраняем регистры на стеке под наше пользование
  21. push ebx
  22.  
  23. finit //инициализируем сопроцессор
  24.  
  25. mov ecx, deg //муваем deg в ecx
  26. mov ebx, 0 //ebx - флажок (1 если deg < 0)
  27. fld number1 //кладем в стек сопроцессора number1
  28. fld1 //кладем в стек сопроцессора 1
  29.  
  30. cmp ecx, 0 //сравнение
  31. jg l //если больше идём в цикл
  32. je endP //если равно идем в конец программы
  33. //если мы сюда зашли => deg < 0
  34. neg ecx //отрицаем ecx (deg)
  35. mov ebx, 1 //ставим флаг на то, что deg < 0
  36.  
  37. l:
  38. cmp ecx, 0 //если deg 0
  39. je endP //идем в конец программы
  40. dec ecx //декриментируем ecx (deg)
  41. cmp ebx, 0 //проверяем значение флага ( deg < 0 ??? )
  42. jg divv //если deg < 0 идем в деление divv
  43. fmul st(0), st(1) //иначе умножаем то, что у нас в стеке сопроцессора и кладем в st(0)
  44. jmp l //прыгаем на l
  45. divv :
  46. fdiv st(0), st(1) //делим то, что у нас в стеке сопроцессора и кладем в st(0)
  47. jmp l //прыгаем на l
  48.  
  49. endP :
  50. fstp res //забираем из стека сопроцессора и кладем в res
  51.  
  52. pop ebx //
  53. pop ecx
  54. }
  55.  
  56. return res;
  57. }
  58.  
  59. void numberEnter(string& str, int numberSystem, char& sign) {
  60. char ch = 0;
  61. while (ch != 13) {
  62. ch = _getch();
  63. if (ch == '-') {
  64. sign *= -1;
  65. cout << ch;
  66. }
  67. else {
  68. if (numberSystem > 36) {
  69. if ((ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch < numberSystem + '0' + 7 + 6)) {
  70. cout << ch;
  71. str += ch;
  72. }
  73. }
  74. else {
  75. if (numberSystem > 10) {
  76. if ((ch >= '0' && ch <= '9') || (ch >= 'A' && ch < numberSystem + '0' + 7)) {
  77. cout << ch;
  78. str += ch;
  79. }
  80. }
  81. else {
  82. if (ch >= '0' && ch < numberSystem + '0') {
  83. cout << ch;
  84. str += ch;
  85. }
  86. }
  87. }
  88. }
  89. }
  90. }
  91.  
  92. void fractionalNumberEnter(string& str, int numberSystem, char& sign, int& dotPos) {
  93. char ch = 0;
  94. int k = 0;
  95. while (ch != 13) {
  96. ch = _getch();
  97. if (ch == '.' && dotPos == -1) {
  98. dotPos = k;
  99. cout << ch;
  100. str += ch;
  101. k++;
  102. }
  103. else {
  104. if ((ch == '-' && str.length() == 0) || (ch == '-' && str[str.length() - 1] == '-')) {
  105. sign *= -1;
  106. cout << ch;
  107. }
  108. else {
  109. if (numberSystem > 36) {
  110. if ((ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch < numberSystem + '0' + 7 + 6)) {
  111. cout << ch;
  112. str += ch;
  113. }
  114. }
  115. else {
  116. if (numberSystem > 10) {
  117. if ((ch >= '0' && ch <= '9') || (ch >= 'A' && ch < numberSystem + '0' + 7)) {
  118. cout << ch;
  119. str += ch;
  120. }
  121. }
  122. else {
  123. if (ch >= '0' && ch < numberSystem + '0') {
  124. cout << ch;
  125. str += ch;
  126. }
  127. }
  128. }
  129. k++;
  130. }
  131. }
  132. }
  133. }
  134.  
  135. void charEnter(string& charEnter) {
  136. char ch = 0;
  137. while (ch != 13/*return*/) {
  138. ch = _getch();
  139. if (ch >= '0' && ch <= '9') {
  140. cout << ch;
  141. charEnter += ch;
  142. }
  143. if ((charEnter[0] > '2' && charEnter.length() >= 2) || (charEnter.length() == 3))
  144. break;
  145. }
  146. }
  147.  
  148. void printAlphabet(int numberSystem) {
  149. cout << "Admissible characters: ";
  150. for (int i = 0; i < numberSystem; i++) {
  151. if (i < 10)
  152. cout << "\t" << char(i + '0') << "-" << i << " ";
  153. if (i >= 10 && i < 36)
  154. cout << "\t" << char(i + '0' + 7) << "-" << i << " ";
  155. if (i >= 36)
  156. cout << "\t" << char(i + '0' + 7 + 6) << "-" << i << " ";
  157. }
  158. cout << endl;
  159. }
  160.  
  161. void colorChoice(short int& color0, short int& color1, HANDLE hConsole) {
  162. cout << "Choose colors for bits!\n";
  163. char ch = '0', choose;
  164. for (int i = 0; i < 10; i++) {
  165. if (i == 0)
  166. SetConsoleTextAttribute(hConsole, (WORD)((15 << 4) | i));
  167. else
  168. SetConsoleTextAttribute(hConsole, (WORD)((0 << 4) | i));
  169. cout << char(254) << char(254) << char(254) << char(254) << char(254) << " - [" << i << "]\n";
  170. }
  171. for (int i = 10; i < 16; i++) {
  172. SetConsoleTextAttribute(hConsole, (WORD)((0 << 4) | i));
  173. cout << char(254) << char(254) << char(254) << char(254) << char(254) << " - [" << char(ch + i + 7) << "]\n";
  174. }
  175. SetConsoleTextAttribute(hConsole, (WORD)((0 << 4) | colordef));
  176. cout << "Choose color for zeros: ";
  177. do {
  178. choose = _getch();
  179. } while (!((choose >= '0' && choose <= '9') || (choose >= 'A' && choose <= 'F')));
  180. if (choose > '9') {
  181. color0 = choose - '0' - 7;
  182. }
  183. else {
  184. color0 = choose - '0';
  185. }
  186. choose = 0;
  187. if (color0 != 0)
  188. SetConsoleTextAttribute(hConsole, (WORD)((0 << 4) | color0));
  189. else
  190. SetConsoleTextAttribute(hConsole, (WORD)((colordef << 4) | color0));
  191. cout << 0 << endl;
  192. SetConsoleTextAttribute(hConsole, (WORD)((0 << 4) | colordef));
  193. cout << "Choose color for units: ";
  194. do {
  195. choose = _getch();
  196. } while (!((choose >= '0' && choose <= '9') || (choose >= 'A' && choose <= 'F')));
  197. if (choose > '9') {
  198. color1 = choose - 7 - '0';
  199. }
  200. else {
  201. color1 = choose - '0';
  202. }
  203. if (color1 != 0)
  204. SetConsoleTextAttribute(hConsole, (WORD)((0 << 4) | color1));
  205. else
  206. SetConsoleTextAttribute(hConsole, (WORD)((colordef << 4) | color1));
  207. cout << 1 << endl;
  208. SetConsoleTextAttribute(hConsole, (WORD)((0 << 4) | colordef));
  209. }
  210.  
  211. void print_graph(int size) {
  212. Gnuplot plot;
  213. string str = "set xrange [-0.25:";
  214. str += to_string(size - 1) + ".25]";
  215. plot(str);
  216. plot("set yrange [-0.25:1.25]");
  217. plot("plot \'E:\\VisualStudio\\projects\\oevm1\\oevm1\\data.txt\' lt 7 lc 22 with linespoints");
  218. cout << endl;
  219. system("pause");
  220. }
  221.  
  222. void bit_print(char* arr, int size, HANDLE hConsole, short int color0, short int color1, bool changing = false, int index = -1, bool graph = false) {
  223. ofstream file("data.txt");
  224. for (int i = size - 1; i >= 0; i--) {
  225. for (int j = 0; j < sizeof(char) * 8; j++) {
  226. int k = (i) * sizeof(char) * 8 + (8 - j - 1);
  227. file << k << " ";
  228. if (arr[i] & 128) {
  229. if (k < 100)
  230. file << 1;
  231. if (changing && k == index) {
  232. SetConsoleTextAttribute(hConsole, (WORD)((15 << 4) | black));
  233. cout << "1";
  234. }
  235. else {
  236. SetConsoleTextAttribute(hConsole, (WORD)((0 << 4) | color1));
  237. cout << "1";
  238. }
  239. }
  240. else {
  241. file << 0;
  242. if (changing && k == index) {
  243. SetConsoleTextAttribute(hConsole, (WORD)((15 << 4) | black));
  244. cout << "0";
  245. }
  246. else {
  247. SetConsoleTextAttribute(hConsole, (WORD)((0 << 4) | color0));
  248. cout << 0;
  249. }
  250. }
  251. arr[i] <<= 1;
  252.  
  253. if (k > 0)
  254. file << "\n";
  255. }
  256. }
  257. SetConsoleTextAttribute(hConsole, (WORD)((0 << 4) | colordef));
  258. file.close();
  259. if (graph)
  260. print_graph(size * 8);
  261. }
  262.  
  263. void bit_print(char ch, short int color0, short int color1, HANDLE hConsole, bool changing = false, int index = -1, bool graph = false) {
  264. ofstream file("data.txt");
  265. for (int i = 0; i < sizeof(char) * 8; i++) {
  266. file << 7 - i << " ";
  267. if (ch & 128) {
  268. file << 1;
  269. if (changing && (8 - i - 1) == index) {
  270. SetConsoleTextAttribute(hConsole, (WORD)((15 << 4) | black));
  271. cout << "1";
  272. }
  273. else {
  274. SetConsoleTextAttribute(hConsole, (WORD)((0 << 4) | color1));
  275. cout << "1";
  276. }
  277. }
  278. else {
  279. file << 0;
  280. if (changing && (8 - i - 1) == index) {
  281. SetConsoleTextAttribute(hConsole, (WORD)((15 << 4) | black));
  282. cout << "0";
  283. }
  284. else {
  285. SetConsoleTextAttribute(hConsole, (WORD)((0 << 4) | color0));
  286. cout << 0;
  287. }
  288. }
  289. ch <<= 1;
  290. file << "\n";
  291. }
  292. SetConsoleTextAttribute(hConsole, (WORD)((0 << 4) | colordef));
  293. file.close();
  294. if (graph)
  295. print_graph(8);
  296. }
  297.  
  298. void bitChange(char& number, HANDLE hConsole, short int color0, short int color1) {
  299. cout << "Enter index of the 1st bit: ";
  300. int index, n;
  301. char temp;
  302. cin >> index;
  303. if (index >= sizeof(char) * 8 || index < 0)
  304. return;
  305. cout << "Enter number of bits that u wanna change: ";
  306. cin >> n;
  307. if (n + index > sizeof(char) * 8) {
  308. cout << "ERROR: number + index is bigger than size of data type\n";
  309. return;
  310. }
  311. 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";
  312. system("pause");
  313. system("cls");
  314. bit_print(number, color0, color1, hConsole, true, index);
  315. char ch = 0;
  316. cout << "Enter bits: ";
  317. int i = index;
  318. while (i < n && ch != 13) {
  319. ch = _getch();
  320. switch (ch) {
  321. case '1':
  322. SetConsoleTextAttribute(hConsole, (WORD)((0 << 4) | color1));
  323. temp = 1;
  324. temp <<= i;
  325. number = number | temp;
  326. system("cls");
  327. bit_print(number, color0, color1, hConsole, true, i + 1);
  328. break;
  329. case '0':
  330. SetConsoleTextAttribute(hConsole, (WORD)((0 << 4) | color0));
  331. temp = -1;
  332. temp -= 1 << i;
  333. number = number & temp;
  334. system("cls");
  335. bit_print(number, color0, color1, hConsole, true, i + 1);
  336. break;
  337. default:
  338. i--;
  339. }
  340. i++;
  341. }
  342. SetConsoleTextAttribute(hConsole, (WORD)((0 << 4) | colordef));
  343. cout << endl;
  344. }
  345.  
  346. void bitChange(int& number, HANDLE hConsole, short int color0, short int color1) {
  347. union {
  348. int _number;
  349. char bytes[sizeof(int)];
  350. };
  351. _number = number;
  352. cout << "Enter index of the 1st bit: ";
  353. int index, temp, n;
  354. cin >> index;
  355. if (index >= sizeof(int) * 8 || index < 0)
  356. return;
  357. cout << "Enter number of bits that u wanna change: ";
  358. cin >> n;
  359. if (n + index > sizeof(float) * 8) {
  360. cout << "ERROR: number + index is bigger than size of data type\n";
  361. return;
  362. }
  363. 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";
  364. system("pause");
  365. system("cls");
  366. bit_print(bytes, sizeof(int), hConsole, color0, color1, true, index);
  367. char ch = 0;
  368. int i = index;
  369. n = n + index;
  370. while (i < n && ch != 13) {
  371. ch = _getch();
  372. switch (ch) {
  373. case '1':
  374. SetConsoleTextAttribute(hConsole, (WORD)((0 << 4) | color1));
  375. temp = 1;
  376. temp <<= i;
  377. number = number | temp;
  378. _number = number;
  379. system("cls");
  380. bit_print(bytes, sizeof(int), hConsole, color0, color1, true, i + 1);
  381. break;
  382. case '0':
  383. SetConsoleTextAttribute(hConsole, (WORD)((0 << 4) | color0));
  384. temp = -1;
  385. temp -= 1 << i;
  386. number = number & temp;
  387. _number = number;
  388. system("cls");
  389. bit_print(bytes, sizeof(int), hConsole, color0, color1, true, i + 1);
  390. break;
  391. default:
  392. i--;
  393. }
  394. i++;
  395. }
  396. SetConsoleTextAttribute(hConsole, (WORD)((0 << 4) | colordef));
  397. cout << endl;
  398. }
  399.  
  400. void bitChange(char* arr, int size, HANDLE hConsole, short int color0, short int color1) {
  401. cout << "Enter index of the 1st bit: ";
  402. int index, n;
  403. char temp;
  404. char temparr[sizeof(double)];
  405. for (int i = 0; i < sizeof(double); ++i) {
  406. temparr[i] = arr[i];
  407. }
  408. cin >> index;
  409. if (index >= sizeof(char) * 8 * size || index < 0)
  410. return;
  411. cout << "Enter number of bits that u wanna change: ";
  412. cin >> n;
  413. if (n + index > sizeof(char) * 8 * size) {
  414. cout << "ERROR: number + index is bigger than size of data type\n";
  415. return;
  416. }
  417. 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";
  418. system("pause");
  419. system("cls");
  420. bit_print(temparr, size, hConsole, color0, color1, true, index);
  421. for (int i = 0; i < sizeof(double); ++i) {
  422. temparr[i] = arr[i];
  423. }
  424. char ch = 0;
  425. int i = index;
  426. while (i < n + index && ch != 13) {
  427. ch = _getch();
  428. switch (ch) {
  429. case '1':
  430. SetConsoleTextAttribute(hConsole, (WORD)((0 << 4) | color1));
  431. temp = 1;
  432. temp <<= i % 8;
  433. arr[i / 8] |= temp;
  434. temparr[i / 8] = arr[i / 8];
  435. system("cls");
  436. bit_print(temparr, size, hConsole, color0, color1, true, i + 1);
  437. for (int i = 0; i < sizeof(double); ++i) {
  438. temparr[i] = arr[i];
  439. }
  440. break;
  441. case '0':
  442. SetConsoleTextAttribute(hConsole, (WORD)((0 << 4) | color0));
  443. temp = -1;
  444. temp -= 1 << i % 8;
  445. arr[i / 8] &= temp;
  446. temparr[i / 8] = arr[i / 8];
  447. system("cls");
  448. bit_print(temparr, size, hConsole, color0, color1, true, i + 1);
  449. for (int i = 0; i < sizeof(double); ++i) {
  450. temparr[i] = arr[i];
  451. }
  452. break;
  453. default:
  454. i--;
  455. }
  456. i++;
  457. }
  458. SetConsoleTextAttribute(hConsole, (WORD)((0 << 4) | colordef));
  459. cout << endl;
  460. }
  461.  
  462. void bitChange(INT64& number, HANDLE hConsole, short int color0, short int color1) {
  463. union {
  464. INT64 _number;
  465. char bytes[sizeof(long long)];
  466. };
  467. _number = number;
  468. cout << "Enter index of the 1st bit: ";
  469. int i, n;
  470. INT64 temp;
  471. cin >> i;
  472. if (i > sizeof(INT64) * 8 || i < 0)
  473. return;
  474. cout << "Enter number of bits that u wanna change: ";
  475. cin >> n;
  476. if (n + i > sizeof(INT64) * 8) {
  477. cout << "ERROR: number + index is bigger than size of data type\n";
  478. return;
  479. }
  480. 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";
  481. system("pause");
  482. system("cls");
  483. bit_print(bytes, sizeof(INT64), hConsole, color0, color1, true, i);
  484. if (i >= sizeof(INT64) * 8 || i < 0)
  485. return;
  486. char ch = 0;
  487. n = n + i;
  488. while (i < n && ch != 13) {
  489. ch = _getch();
  490. switch (ch) {
  491. case '1':
  492. SetConsoleTextAttribute(hConsole, (WORD)((0 << 4) | color1));
  493. temp = 1;
  494. temp <<= i;
  495. number = number | temp;
  496. _number = number;
  497. system("cls");
  498. bit_print(bytes, sizeof(INT64), hConsole, color0, color1, true, i + 1);
  499. break;
  500. case '0':
  501. SetConsoleTextAttribute(hConsole, (WORD)((0 << 4) | color0));
  502. temp = -1;
  503. temp -= 1 << i;
  504. number = number & temp;
  505. _number = number;
  506. system("cls");
  507. bit_print(bytes, sizeof(INT64), hConsole, color0, color1, true, i + 1);
  508. break;
  509. default:
  510. i--;
  511. }
  512. i++;
  513. }
  514. SetConsoleTextAttribute(hConsole, (WORD)((0 << 4) | colordef));
  515. cout << endl;
  516. }
  517.  
  518. void int_processing(int numberSystem, HANDLE hConsole) {
  519. union {
  520. int number;
  521. char bytes[sizeof(int)];
  522. };
  523. number = 0;
  524. char sign = 1;
  525. string intEnter = "";
  526. system("cls");
  527. cout << "INT " << numberSystem << " system\n";
  528. printAlphabet(numberSystem);
  529. cout << "Enter number: ";
  530. numberEnter(intEnter, numberSystem, sign);
  531. for (int i = 0; i < intEnter.length(); i++) {
  532. if (intEnter[i] >= 'a') {
  533. number += (intEnter[i] - '0' - 7 - 6) * degree(intEnter.length() - i - 1, numberSystem);
  534. }
  535. else {
  536. if (intEnter[i] >= 'A') {
  537. number += (intEnter[i] - '0' - 7) * degree(intEnter.length() - i - 1, numberSystem);
  538. }
  539. else {
  540. number += (intEnter[i] - '0') * degree(intEnter.length() - i - 1, numberSystem);
  541. }
  542. }
  543. }
  544. number *= sign;
  545. cout << endl;
  546. short int color0, color1;
  547. colorChoice(color0, color1, hConsole);
  548. cout << "decimal notation: " << number << endl;
  549. int temp;
  550. temp = number;
  551. cout << "binary notation: ";
  552. bit_print(bytes, sizeof(int), hConsole, color0, color1, false, -1, true);
  553. cout << endl;
  554. char exitcode;
  555. do {
  556. cout << "Dou you want to change some bits?\n[y] - yes\n[n] - no";
  557. char ch = 0;
  558. do {
  559. ch = _getch();
  560. } while (ch != 'y' && ch != 'n');
  561. cout << endl;
  562. if (ch == 'y') {
  563. bitChange(temp, hConsole, color0, color1);
  564. number = temp;
  565. cout << "changed demical notation: " << number << endl;
  566. cout << "changed binary notation: ";
  567. bit_print(bytes, sizeof(int), hConsole, color0, color1, false, -1, true);
  568. cout << endl;
  569. }
  570. cout << "Press ECS to exit, RETURN to continue...\n";
  571. do {
  572. exitcode = _getch();
  573. } while (exitcode != 27 && exitcode != 13);
  574. } while (exitcode != 27);
  575. system("cls");
  576. }
  577.  
  578. void float_proccesing(int numberSystem, HANDLE hConsole) {
  579. union {
  580. float number;
  581. int inumber;
  582. char bytes[sizeof(float)];
  583. };
  584. number = 0;
  585. char sign2 = 1;
  586. int dotPos = -1;
  587. string floatEnter = "";
  588. system("cls");
  589. cout << "FLOAT " << numberSystem << " system\n";
  590. printAlphabet(numberSystem);
  591. cout << "Enter number: ";
  592. fractionalNumberEnter(floatEnter, numberSystem, sign2, dotPos);
  593. if (dotPos != -1) {
  594. for (int i = 0; i < dotPos; i++) {
  595. if (floatEnter[i] - '0' < 10)
  596.  
  597. number += (floatEnter[i] - '0') * degree(dotPos - i - 1, numberSystem);
  598. else {
  599. if (floatEnter[i] <= 'Z') {
  600. number += (floatEnter[i] - '0' - 7 /*number that deletes the difference between the character A and number 10*/) * degree(dotPos - i - 1, numberSystem);
  601. }
  602. else {
  603. number += (floatEnter[i] - '0' - 7 - 6 /*number that deletes the difference between the character a and 10*/) * degree(dotPos - i - 1, numberSystem);
  604. }
  605. }
  606. }
  607. for (int i = dotPos + 1; i < floatEnter.length(); i++) {
  608. if (floatEnter[i] - '0' < 10)
  609. number += (floatEnter[i] - '0') * degree(dotPos - i, numberSystem);
  610. else {
  611. if (floatEnter[i] <= 'Z') {
  612. number += (floatEnter[i] - '0' - 7 /*number that deletes the difference between the character A and number 10*/) * degree(dotPos - i, numberSystem);
  613. }
  614. else {
  615. number += (floatEnter[i] - '0' - 7 - 6 /*number that deletes the difference between the character a and number 10*/) * degree(dotPos - i, numberSystem);
  616. }
  617. }
  618. }
  619. }
  620. else {
  621. for (int i = 0; i < floatEnter.length(); i++) {
  622. if (floatEnter[i] - '0' < 10) {
  623. number += (floatEnter[i] - '0') * degree(floatEnter.length() - i - 1, numberSystem);
  624. }
  625. else {
  626. number += (floatEnter[i] - '0' - 7 /*number that deletes the difference between the character A and number 10*/) * degree(floatEnter.length() - i - 1, numberSystem);
  627. }
  628. }
  629. }
  630. number *= sign2;
  631. cout << endl;
  632. short int color0, color1;
  633. colorChoice(color0, color1, hConsole);
  634. cout << "decimal notation: " << fixed << number << endl;
  635. int temp;
  636. temp = inumber;
  637. cout << "binary notation: ";
  638. bit_print(bytes, sizeof(float), hConsole, color0, color1, false, -1, true);
  639. cout << endl;
  640. char exitcode;
  641. do {
  642. cout << "Dou you want to change some bits?\n[y] - yes\n[n] - no";
  643. char chr;
  644. chr = 0;
  645. do {
  646. chr = _getch();
  647. } while (chr != 'y' && chr != 'n');
  648. cout << endl;
  649. if (chr == 'y') {
  650. bitChange(temp, hConsole, color0, color1);
  651. inumber = temp;
  652. cout.unsetf(ios::fixed);
  653. cout << "changed demical notation: " << number << endl;
  654. cout << "changed binary notation: ";
  655. bit_print(bytes, sizeof(float), hConsole, color0, color1, false, -1, true);
  656. cout << endl;
  657. }
  658. cout << "Press ESC to exit, RETURN to continue...\n";
  659. do {
  660. exitcode = _getch();
  661. } while (exitcode != 27 && exitcode != 13);
  662. } while (exitcode != 27);
  663. system("cls");
  664. }
  665.  
  666. void double_proccesing(int numberSystem, HANDLE hConsole) {
  667. union {
  668. double number;
  669. char bytes[sizeof(double)];
  670. };
  671. number = 0;
  672. char sign3 = 1;
  673. int dotPos2 = -1;
  674. string doubleEnter = "";
  675. system("cls");
  676. cout << "DOUBLE " << numberSystem << " system\n";
  677. printAlphabet(numberSystem);
  678. cout << "Enter number: ";
  679. fractionalNumberEnter(doubleEnter, numberSystem, sign3, dotPos2);
  680. if (dotPos2 != -1) {
  681. for (int i = 0; i < dotPos2; i++) {
  682. if (doubleEnter[i] - '0' < 10)
  683. number += (doubleEnter[i] - '0') * degree(dotPos2 - i - 1, numberSystem);
  684. else {
  685. if (doubleEnter[i] <= 'Z') {
  686. number += (doubleEnter[i] - '0' - 7 /*number that deletes the difference between the character A and number 10*/) * degree(dotPos2 - i - 1, numberSystem);
  687. }
  688. else {
  689. number += (doubleEnter[i] - '0' - 7 - 6 /*number that deletes the difference between the character a and 10*/) * degree(dotPos2 - i - 1, numberSystem);
  690. }
  691. }
  692. }
  693. for (int i = dotPos2 + 1; i < doubleEnter.length(); i++) {
  694. if (doubleEnter[i] - '0' < 10)
  695. number += (doubleEnter[i] - '0') * degree(dotPos2 - i, numberSystem);
  696. else {
  697. if (doubleEnter[i] <= 'Z') {
  698. number += (doubleEnter[i] - '0' - 7 /*number that deletes the difference between the character A and number 10*/) * degree(dotPos2 - i, numberSystem);
  699. }
  700. else {
  701. number += (doubleEnter[i] - '0' - 7 - 6 /*number that deletes the difference between the character a and number 10*/) * degree(dotPos2 - i, numberSystem);
  702. }
  703. }
  704. }
  705. }
  706. else {
  707. for (int i = 0; i < doubleEnter.length(); i++) {
  708. if (doubleEnter[i] - '0' < 10) {
  709. number += (doubleEnter[i] - '0') * degree(doubleEnter.length() - i - 1, numberSystem);
  710. }
  711. else {
  712. if (doubleEnter[i] <= 'Z') {
  713. number += (doubleEnter[i] - '0' - 7 /*number that deletes the difference between the character A and number 10*/) * degree(doubleEnter.length() - i - 1, numberSystem);
  714. }
  715. else {
  716. number += (doubleEnter[i] - '0' - 7 - 6 /*number that deletes the difference between the character A and number 10*/) * degree(doubleEnter.length() - i - 1, numberSystem);
  717. }
  718. }
  719. }
  720. }
  721. number *= sign3;
  722. cout << endl;
  723. short int color0, color1;
  724. colorChoice(color0, color1, hConsole);
  725. cout << "decimal notation: " << fixed << number << endl;
  726. char temp[sizeof(double)];
  727. for (int i = 0; i < sizeof(double); ++i) {
  728. temp[i] = bytes[i];
  729. }
  730. cout << "binary notation: ";
  731. bit_print(bytes, sizeof(double), hConsole, color0, color1, false, -1, true);
  732. cout << endl;
  733. char exitcode;
  734. do {
  735. cout << "Dou you want to change some bits?\n[y] - yes\n[n] - no";
  736. char c;
  737. c = 0;
  738. do {
  739. c = _getch();
  740. } while (c != 'y' && c != 'n');
  741. cout << endl;
  742. if (c == 'y') {
  743. bitChange(temp, sizeof(double), hConsole, color0, color1);
  744. for (int i = 0; i < sizeof(double); ++i) {
  745. bytes[i] = temp[i];
  746. }
  747. cout.unsetf(ios::fixed);
  748. cout << "changed demical notation: " << number << endl;
  749. cout << "changed binary notation: ";
  750. bit_print(bytes, sizeof(double), hConsole, color0, color1, false, -1, true);
  751. cout << endl;
  752. }
  753. cout << "Press ESC to exit, RETURN to continue...\n";
  754. do {
  755. exitcode = _getch();
  756. } while (exitcode != 27 && exitcode != 13);
  757. } while (exitcode != 27);
  758. system("cls");
  759. }
  760.  
  761. void char_proccesing(HANDLE hConsole) {
  762. system("cls");
  763. cout << "CHAR\n";
  764. char task = 0, character = 0;
  765. string charString = "";
  766. do {
  767. cout << "[1] - character itself\n" << "[2] - code of character";
  768. task = _getch();
  769. if (task != '1' && task != '2') {
  770. system("cls");
  771. cout << "ERROR: Wrong enter!\n";
  772. }
  773. } while (task != '1' && task != '2');
  774. if (task == '1') {
  775. cout << "\nEnter a character: ";
  776. character = _getch();
  777. cout << character << endl;
  778. cout << "Code: " << int(character) << endl;
  779. }
  780. else {
  781. cout << "\nEnter code of character: ";
  782. charEnter(charString);
  783. for (int i = 0; i < charString.length(); i++) {
  784. character += (charString[i] - '0') * degree(charString.length() - i - 1, 10);
  785. }
  786. cout << "\nCharacter: " << character << endl;
  787. }
  788. short int color0, color1;
  789. colorChoice(color0, color1, hConsole);
  790. char temp = character;
  791. cout << "binary notation: ";
  792. bit_print(character, color0, color1, hConsole, false, -1, true);
  793. cout << endl;
  794. char exitcode;
  795. do {
  796. cout << "Dou you want to change some bits?\n[y] - yes\n[n] - no";
  797. char c;
  798. c = 0;
  799. do {
  800. c = _getch();
  801. } while (c != 'y' && c != 'n');
  802. cout << endl;
  803. if (c == 'y') {
  804. bitChange(temp, hConsole, color0, color1);
  805. character = temp;
  806. cout << "changed demical notation: " << int(character) << endl;
  807. cout << "changed character itself: " << character << endl;
  808. cout << "changed binary notation: ";
  809. bit_print(character, color0, color1, hConsole, false, -1, true);
  810. cout << endl;
  811. }
  812. cout << "Press ESC to exit, RETURN to continue...\n";
  813. do {
  814. exitcode = _getch();
  815. } while (exitcode != 27 && exitcode != 13);
  816. } while (exitcode != 27);
  817. system("cls");
  818. cout << "Press ECS to exit...";
  819. system("cls");
  820. }
  821.  
  822. void bool_proccesing(HANDLE hConsole) {
  823. union {
  824. bool flag;
  825. char help;
  826. };
  827. system("cls");
  828. cout << "BOOL\n";
  829. cout << "Enter smt: ";
  830. help = _getch();
  831. cout << help;
  832. if (help == '0')
  833. flag = 0;
  834. else
  835. flag = 1;
  836. cout << endl;
  837. short int color0, color1;
  838. colorChoice(color0, color1, hConsole);
  839. cout << int(&flag) << " " << int(&help) << endl;
  840. cout << "You entered: " << boolalpha << flag << endl;
  841. cout << "binary notation: ";
  842. bit_print(help, color0, color1, hConsole, false, -1, true);
  843. cout << endl;
  844. cout << "Press ECS to exit...";
  845. char exitcode;
  846. do {
  847. exitcode = _getch();
  848. } while (exitcode != 27);
  849. system("cls");
  850. }
  851.  
  852. void numberSystem_proccesing(int& numberSystem) {
  853. char ch = 0;
  854. string numberSystemEnter = "";
  855. do {
  856. cout << "Enter number system (2-62): ";
  857. while (numberSystemEnter.length() < 2 && ch != 13/*return*/) {
  858. ch = _getch();
  859. if (ch >= '0' && ch <= '9') {
  860. if (!(ch == '0' && numberSystemEnter.length() == 0)) {
  861. cout << ch;
  862. numberSystemEnter += ch;
  863. }
  864. }
  865. if (numberSystemEnter.length() == 1 && numberSystemEnter[0] > '6') {
  866. break;
  867. }
  868. }
  869. for (int i = 0; i < numberSystemEnter.length(); i++) {
  870. numberSystem += (numberSystemEnter[i] - '0') * degree(numberSystemEnter.length() - i - 1, 10);
  871. }
  872. if (numberSystem > 62 || numberSystem < 2) {
  873. system("cls");
  874. cout << "ERROR: Wrong enter!" << endl;
  875. ch = 0;
  876. numberSystem = 0;
  877. numberSystemEnter = "";
  878. }
  879. } while (numberSystem < 2 || numberSystem > 62);
  880. }
  881.  
  882. int main()
  883. {
  884. HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
  885.  
  886. Gnuplot plot;
  887.  
  888. char dataType;
  889. do {
  890. int numberSystem = 0;
  891. cout << "Enter data type\n" << "[1] - int\n" << "[2] - float\n"
  892. << "[3] - double\n" << "[4] - char\n" << "[5] - bool\n" << "[ESC] - exit\n";
  893. dataType = _getch();
  894. if (dataType == '1' || dataType == '2' || dataType == '3') {
  895. system("cls");
  896. numberSystem_proccesing(numberSystem);
  897. }
  898. switch (dataType) {
  899. case '1' /*int*/:
  900. int_processing(numberSystem, hConsole);
  901. break;
  902. case '2' /*float*/:
  903. float_proccesing(numberSystem, hConsole);
  904. break;
  905. case '3' /*double*/:
  906. double_proccesing(numberSystem, hConsole);
  907. break;
  908. case '4' /*char*/:
  909. char_proccesing(hConsole);
  910. break;
  911. case '5'/*bool*/:
  912. bool_proccesing(hConsole);
  913. break;
  914. default:
  915. system("cls");
  916. cout << "ERROR: Wrong enter!\n";
  917. }
  918. } while (dataType != 27 /*esc*/);
  919. return 0;
  920. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement