Advertisement
B1LLy

#9a programowanie - lab

Dec 5th, 2016
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.00 KB | None | 0 0
  1. TO DZIAŁA XDDDDDD program z zajęć - wyświetlenie liczby dziesiętnej w postaci binarnej (na tablicy, max. 2^32-1)
  2. ----------------------------------------------------------------------------------------------------------------
  3. // ConsoleApplication17.cpp : Defines the entry point for the console application.
  4. //
  5.  
  6. #include "stdafx.h"
  7. #include <iostream>
  8. using namespace std;
  9.  
  10. void do_binar(unsigned int i, int tab[32]);
  11.  
  12. int main()
  13. {
  14.     unsigned int ibity;
  15.     int nrbitu, iwart, ispr;
  16.     int tab[32];
  17.    
  18.     cout <<"rozmiar"<< sizeof(unsigned int) << endl;
  19.  
  20.     cout << "wpisywanie bitow:" << endl;
  21.     cout << "podaj bity jako liczbe calkowita  ";
  22.     cin >> ibity;
  23.     do_binar(ibity, tab);
  24.     for (int ii = 31; ii >= 0; ii--)
  25.     {
  26.         cout << " " << tab[ii];
  27.         if (ii % 8 == 0)cout << "  ";
  28.     }
  29.     getchar();
  30.     getchar();
  31.  
  32.  
  33.     return 0;
  34. }
  35.  
  36. void do_binar(unsigned int i, int tab[32])
  37. {
  38.     unsigned int ilicz, irob;
  39.     irob = i;
  40.     for (ilicz = 0; ilicz <= 31; ilicz++)
  41.     {
  42.         tab[ilicz] = irob % 2;
  43.         irob /= 2;
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement