Glenpl

binary field and union

Nov 14th, 2014
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3.  
  4. using namespace std;
  5.  
  6. struct pola_bitowe
  7. {
  8.     bool b1 :1;
  9.     bool b2 :1;
  10.     bool b3 :1;
  11.     bool b4 :1;
  12.     bool b5 :1;
  13.     bool b6 :1;
  14.     bool b7 :1;
  15.     bool b8 :1;
  16. };
  17.  
  18. union
  19. {
  20.     unsigned char znak;
  21.     pola_bitowe pb;
  22. } ddd;
  23.  
  24. int main()
  25. {
  26.     string imie;
  27.     cout<<"Podaj swoje imie: ";
  28.     cin>>imie;
  29.     for(unsigned int i =0; i<imie.length(); i++)
  30.     {
  31.         cout<<endl<<imie[i]<<" = ";
  32.         ddd.znak = imie[i];
  33.         cout<<ddd.pb.b8<<ddd.pb.b7<<ddd.pb.b6<<ddd.pb.b5<<ddd.pb.b4<<ddd.pb.b3<<ddd.pb.b2<<ddd.pb.b1;
  34.         cout<<endl;
  35.     }
  36.  
  37.     getch();
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment