Advertisement
FokaKefir

Bitműveletek

Nov 7th, 2019
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.89 KB | None | 0 0
  1. int utolsoBit(int n){
  2.     return ((n>>1)<<1)^n;
  3. }
  4.  
  5. //1. Feladat
  6. void titkosit(int n){
  7.     n= n^1;
  8.     n= n^1;
  9.     cout<< n << '\n';
  10. }
  11.  
  12. //2. Feladat
  13. void kiKetBajton(int n){
  14.     for (int i = 0; i < 16; ++i) {
  15.         int k= utolsoBit(n);
  16.         cout<<k<<'\n';
  17.         n= n>>1;
  18.     }
  19.     return;
  20. }
  21.  
  22. //3. Feladat
  23. void bitrotacioPozicio(int n, int ind){
  24.     ind++;
  25.     int k=0;
  26.     for (int i = 0; i <ind; ++i) {
  27.         k=(k<<1);
  28.         k=k | (utolsoBit(n));
  29.         n= n>>1;
  30.     }
  31.     n= n<<(ind);
  32.     n= n | k;
  33.     cout<<n;
  34. }
  35.  
  36. //4. Feladat
  37. int swapKetBajton(int &n){
  38.     int ind= 16;
  39.     int k= 0;
  40.     for (int i = 0; i <ind; ++i) {
  41.         k=(k<<1);
  42.         k=k | (utolsoBit(n));
  43.         n= n>>1;
  44.     }
  45.     n=k;
  46.     cout<<n<<'\n';
  47.     return n;
  48.  
  49. }
  50.  
  51. //5. Feladat
  52. void korbeforgatAdottPozicio(int n, int ind){
  53.    
  54. }
  55.  
  56. //6. Feladat
  57. void rekFonokok(){
  58.    
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement