Advertisement
B1LLy

#9b programowanie - lab

Dec 5th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.84 KB | None | 0 0
  1. //cały program, połączony, tez jakims cudem działa
  2. -------------------------------------------------------
  3.  
  4. // ConsoleApplication17.cpp : Defines the entry point for the console application.
  5. //
  6.  
  7. #include "stdafx.h"
  8. #include <iostream>
  9. using namespace std;
  10.  
  11. void do_binar(unsigned int i, int tab[32]);
  12.  
  13. void dawaj_bita(unsigned int &bity, int nrbitu, int ktorybit)
  14. {
  15.     unsigned int irob;
  16.  
  17.     if (nrbitu > 31)
  18.     {
  19.         cout << "funkcja dawaj_bita: numer bitu musi byc mniejszy";
  20.         cout << "koniec....press any key...." << endl;
  21.             getchar();
  22.             getchar();
  23.             exit(0);
  24.     };
  25.     irob = 1;
  26.     irob = irob << nrbitu;
  27.  
  28.     if (ktorybit == 0)
  29.     {
  30.         bity = bity&(~irob);
  31.     }
  32.     else if (ktorybit == 1)
  33.     {
  34.         bity = bity | irob;
  35.     }
  36.     else
  37.     {
  38.         cout << "funkcja dawaj_bita: bit moze byc 0 albo 1" << endl;
  39.         cout << "koniec....press any key...";
  40.         getchar();
  41.         getchar();
  42.         exit(0);
  43.     }
  44. }
  45.  
  46. int main()
  47. {
  48.     unsigned int ibity;
  49.     int nrbitu, iwart, ispr;
  50.     int tab[32];
  51.    
  52.     // cout <<"rozmiar"<< sizeof(unsigned int) << endl;
  53.  
  54.     cout << "wpisywanie bitow:" << endl;
  55.     cout << "podaj bity jako liczbe calkowita  ";
  56.     cin >> ibity;
  57.     do_binar(ibity, tab);
  58.     for (int ii = 31; ii >= 0; ii--)
  59.     {
  60.         cout << " " << tab[ii];
  61.         if (ii % 8 == 0)cout << " ";
  62.     }
  63.     cout << endl;
  64.     //ustaw_bit = (u mnie) dawaj_bita
  65.     cout << "podaj numer bitu: " << endl;
  66.     cin >> nrbitu;
  67.     cout << "podaj wartosc bitu: " << endl;
  68.     cin >> iwart;
  69.     dawaj_bita(ibity, nrbitu, iwart);
  70.     cout << "nowa wartosc: " << endl << endl;
  71.     do_binar(ibity, tab);
  72.     for (int ii = 31; ii >= 0; ii--)
  73.     {
  74.         cout << " " << tab[ii];
  75.         if (ii % 8 == 0) cout << " ";
  76.     }
  77.     cout << endl;
  78.     getchar();
  79.     getchar();
  80.  
  81.  
  82.     return 0;
  83. }
  84.  
  85. void do_binar(unsigned int i, int tab[32])
  86. {
  87.     unsigned int ilicz, irob;
  88.     irob = i;
  89.     for (ilicz = 0; ilicz <= 31; ilicz++)
  90.     {
  91.         tab[ilicz] = irob % 2;
  92.         irob /= 2;
  93.     }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement