Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- using namespace std;
- void print8b(unsigned long cislo)
- {
- int i=8;
- while(i--) if(cislo & (1<<i)) printf("1");
- else printf("0");
- }
- int main()
- {
- int c1, c2, p1, p2;
- int d=0, posun=0, sd=0, sp=0, rd=0, rp=0;
- unsigned int bit;
- char pole[20];
- cout << "Zadej prvni cislo: " ;
- cin >> c1;
- cout << "Zadej druhe cislo: ";
- cin >> c2;
- cout << "\nCislo 1 je: " << c1 << endl;
- cout << "Cislo 2 je: " << c2 << endl;
- cout << "----------------------------------------" << endl;
- cout << "\nCislo " << c1 << " v bin je: ";
- print8b(c1);
- cout << "\nCislo " << c2 << " v bin je: ";
- print8b(c2);
- cout << "\n\n----------------------------------------" << endl;
- posun = pow(2.0, 7) - 1;
- p1 = c1 + posun;
- p2 = c2 + posun;
- cout << "\nPosun cisel je o: " << posun << endl;
- cout << "Cislo " << c1 << " v posunuti je: ";
- print8b(p1);
- cout << "\nCislo " << c2 << " v posunuti je: ";
- print8b(p2);
- cout << "\n\n----------------------------------------" << endl;
- sd = p1 + p2 + 2;
- if(sd >= 256)
- sd -= 256;
- sp = sd + posun;
- if(c2 >= 0) {
- cout << "\nSoucet techto cisel v desitkove soustave je: " << sd << endl;
- cout << "Soucet v posunuti je: " << sp << endl;
- cout << "\n----------------------------------------" << endl;
- }
- else {
- cout << "\nRozdil techto cisel v desitkove soustave je: " << sd << endl;
- cout << "Rozdil v posunuti je: " << sp << endl;
- cout << "\n----------------------------------------" << endl;
- }
- d = 1 + ~c2;
- cout << "\nDvojkovy doplnek je: ";
- print8b(d);
- cout << "\n\nRozdil cisel je: " << c1 + d << endl;
- system ("pause");
- }
Add Comment
Please, Sign In to add comment