Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <stdio.h>
- #include <conio.h>
- #include <math.h>
- #include <stdlib.h>
- #include <string.h>
- #include <Windows.h>
- #include <iostream>
- using namespace std;
- char* Dvoichnaya(int x)
- {
- char* t = (char*)malloc(100);
- int i = 0;
- do
- {
- t[i++] = x % 2 + 48;
- x = x / 2;
- } while (x != 0);
- t[i] = '\0';
- int k = strlen(t) - 2;
- int m = k / 2;
- for (int i = 0; i <= m; i++)
- {
- char tmp = t[i];
- t[i] = t[k - i + 1];
- t[k - i + 1] = tmp;
- }
- return t;
- free(t);
- }
- char* DvoichnayaDrob(float x)
- {
- char* t = (char*)malloc(100);
- int i = 0;
- do
- {
- x *= 2;
- if (x >= 1) { t[i++] = '1'; x -= 1; }
- else { t[i++] = '0'; }
- } while (i != 32);
- t[i] = '\0';
- return t;
- free(t);
- }
- int main()
- {
- SetConsoleCP(1251);
- SetConsoleOutputCP(1251);
- int che = 0, k = 1;
- int num;
- int i = 0;
- int step = 0, ish, a, ch = 0;
- int ot = 0;
- float str, po = 0;
- char finch[100], final[33];
- int z;
- scanf("%e", &str);
- if (str >= 0) { final[0] = '0'; }
- else { final[0] = '1'; }
- str = fabs(str);
- char* otm = (char*)malloc(100), * pom = (char*)malloc(100);
- ot = str;
- po = str - ot;
- otm = Dvoichnaya(ot);
- pom = DvoichnayaDrob(po);
- for (int i = 0; i <= strlen(otm); i++) { finch[i] = otm[i]; }
- finch[strlen(otm)] = '.';
- for (int i = 0; i <= strlen(pom); i++) { finch[i + strlen(otm) + 1] = pom[i]; }
- for (int i = 0; finch[1] != '.'; i++, step++)
- {
- char tmp = 0;
- tmp = finch[strlen(otm) - i];
- finch[strlen(otm) - i] = finch[strlen(otm) - i - 1];
- finch[strlen(otm) - i - 1] = tmp;
- }
- step += 127;
- if (step > 127) { otm = Dvoichnaya(step); }
- else { for (i = 0; i <= 7; i++) { otm[i] = '0'; otm[8] = '\0'; } }
- for (int i = 0; i <= strlen(otm); i++) {
- final[i + 1] = otm[i];
- }
- for (int i = 0; (i <= strlen(finch - 2)) && (i <= 23); i++) {
- final[i + 9] = finch[i + 2];
- }
- final[32] = '\0';
- cout << "\n";
- printf("Число во внутреннем представлении компьютера: %s\n", final);
- cout << "\n";
- if (final[0] == '1')
- cout << "Знак: " << " " << final[0] << " (отрицательный)";
- if (final[0] == '0')
- cout << "Знак: " << " " << final[0] << " (положительный)";
- cout << "\n";
- cout << "\n";
- cout << "Экспонента: " << "\t";
- for (int i = 1; i < 9; i++)
- {
- cout << final[i];
- }
- cout << "\n";
- cout << "\n";
- cout << "Мантисса: " << "\t";
- for (int i = 9; i < 32; i++)
- {
- cout << final[i];
- }
- cout << "\n" << endl;
- return 0;
- }
Add Comment
Please, Sign In to add comment