Advertisement
Guest User

testTP_R2

a guest
Apr 7th, 2020
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.72 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNING
  2. #include <stdio.h>
  3. int stack[100];
  4. int top = -1;
  5. void Push(int elem)
  6. {
  7.     stack[++top] = elem;
  8. }
  9. int Pop(void)
  10. {
  11.     return stack[top--];
  12. }
  13.  
  14. int main()
  15. {
  16.     int v[] = { 0x45,0x12,0xF0 };
  17.     for (int i = 0; i < 3; i++) {
  18.         Push(v[i] & 15);
  19.         printf("%x\n", stack[top]);
  20.         Push((v[i] >> 4) & 15);
  21.         printf("%x\n", stack[top]);
  22.     }
  23.     int x, y,nr; // x-elementul scos din stiva
  24.                 // y-salvez in variabila y elementul x pentru afisare la sfarsit
  25.                 // nr-contorul care numara bitii din fiecare nibble
  26.     while (top != -1)
  27.     {
  28.         x=Pop();
  29.         y = x;
  30.         nr = 0;
  31.         while (x) {
  32.             if (x & 1) {
  33.                 nr++;
  34.             }
  35.             x = x >> 1;
  36.         }
  37.         printf("%x are %x biti pe 1\n",y, nr);
  38.     }
  39.     _getch();
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement