Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNING
- #include <stdio.h>
- int stack[100];
- int top = -1;
- void Push(int elem)
- {
- stack[++top] = elem;
- }
- int Pop(void)
- {
- return stack[top--];
- }
- int main()
- {
- int v[] = { 0x45,0x12,0xF0 };
- for (int i = 0; i < 3; i++) {
- Push(v[i] & 15);
- printf("%x\n", stack[top]);
- Push((v[i] >> 4) & 15);
- printf("%x\n", stack[top]);
- }
- int x, y,nr; // x-elementul scos din stiva
- // y-salvez in variabila y elementul x pentru afisare la sfarsit
- // nr-contorul care numara bitii din fiecare nibble
- while (top != -1)
- {
- x=Pop();
- y = x;
- nr = 0;
- while (x) {
- if (x & 1) {
- nr++;
- }
- x = x >> 1;
- }
- printf("%x are %x biti pe 1\n",y, nr);
- }
- _getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement