Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- unsigned short st[11], varf;
- void push(unsigned short x) {
- if (varf > 9) return;
- st[++varf] = x;
- }
- void pop() {
- if (varf == 0) return;
- unsigned short copie = st[varf], nrBit = 0;
- while (copie) {
- nrBit++;
- copie &= copie - 1;
- }
- copie = st[varf];
- printf("pop %ld\n", st[varf]);
- printf("Numarul de biti = 1: %hd\n", nrBit);
- copie &= ~(1 << 2);
- printf("Numarul dupa mascarea bitului 2: %hd\n", copie);
- st[varf] &= ~(1 << 6);
- printf("Numarul dupa bitul 6 devine 0: %hd\n\n", st[varf]);
- varf--;
- }
- int main(){
- unsigned short x, i;
- for (i = 1; i < 8; i++) {
- printf("st[%d]= ", i);
- scanf("%hd", &x);
- push(x);
- }
- for (i = 1; i < 8; i++)pop();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement