Guest User

Untitled

a guest
Jul 15th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3.  
  4. using namespace std;
  5.  
  6. void print8b(unsigned long cislo)
  7. {
  8. int i=8;
  9. while(i--) if(cislo & (1<<i)) printf("1");
  10. else printf("0");
  11. }
  12.  
  13. int main()
  14. {
  15. int c1, c2, p1, p2;
  16. int d=0, posun=0, sd=0, sp=0, rd=0, rp=0;
  17. unsigned int bit;
  18. char pole[20];
  19.  
  20. cout << "Zadej prvni cislo: " ;
  21. cin >> c1;
  22. cout << "Zadej druhe cislo: ";
  23. cin >> c2;
  24.  
  25.  
  26. cout << "\nCislo 1 je: " << c1 << endl;
  27. cout << "Cislo 2 je: " << c2 << endl;
  28. cout << "----------------------------------------" << endl;
  29.  
  30. cout << "\nCislo " << c1 << " v bin je: ";
  31. print8b(c1);
  32. cout << "\nCislo " << c2 << " v bin je: ";
  33. print8b(c2);
  34. cout << "\n\n----------------------------------------" << endl;
  35.  
  36. posun = pow(2.0, 7) - 1;
  37. p1 = c1 + posun;
  38. p2 = c2 + posun;
  39.  
  40. cout << "\nPosun cisel je o: " << posun << endl;
  41. cout << "Cislo " << c1 << " v posunuti je: ";
  42. print8b(p1);
  43. cout << "\nCislo " << c2 << " v posunuti je: ";
  44. print8b(p2);
  45. cout << "\n\n----------------------------------------" << endl;
  46.  
  47. sd = p1 + p2 + 2;
  48. if(sd >= 256)
  49. sd -= 256;
  50. sp = sd + posun;
  51.  
  52. if(c2 >= 0) {
  53. cout << "\nSoucet techto cisel v desitkove soustave je: " << sd << endl;
  54. cout << "Soucet v posunuti je: " << sp << endl;
  55. cout << "\n----------------------------------------" << endl;
  56. }
  57. else {
  58. cout << "\nRozdil techto cisel v desitkove soustave je: " << sd << endl;
  59. cout << "Rozdil v posunuti je: " << sp << endl;
  60. cout << "\n----------------------------------------" << endl;
  61. }
  62.  
  63. d = 1 + ~c2;
  64.  
  65. cout << "\nDvojkovy doplnek je: ";
  66. print8b(d);
  67. cout << "\n\nRozdil cisel je: " << c1 + d << endl;
  68.  
  69. system ("pause");
  70. }
Add Comment
Please, Sign In to add comment